Try a google search for SQL +joins and you should find a wealth of information. Since you're using Access 2000, you can always use the query wizard to construct the query you want, and then use the SQL view to grab the exact SQL statement for your perl script. Sometimes it takes some tweaking to get it right so it runs efficiently, but it's a place to start. The syntax of the end result depends on how you have your tables constructed, how you connect your data, and how exactly you want it all to connect in your output. | [reply] |
I did the Goggle thing, but since I wasn't exactly sure what I was looking for, I just kinda floundered. I did read a number of tutorials on the various types of joins, and they didn't seem to fulfill my requirements. It looks like I will have to use 2 separate queries, and then tie the results together using plain old perl.
Thanks for your input,
digger
| [reply] |
To reduce the number of queries you send to the database, along with the associated round-trip delay, you could 'SELECT County FROM Counties WHERE ' . join(' OR ', map "ID = $_", @current_member_ids) . ' order by ID' and then loop over the results building the associations for each member record.
(Also note that Access may also support an alternative to that OR list using a syntax like "ID is in (7, 12, 42)"; and as a general rule, you should consider using placeholders instead of embedded values in literal queries as shown above.)
It's true that you can't do it all in one query, for the reasons mentioned in other replies, but doing it in a constant two queries and a foreach loop is definitely better than doing hundreds of separate queries, one for each match. | [reply] [d/l] |
I din't think about using the "ID is IN (list") syntax. I am giving that a try right now. It will take a little coercion to get the data into usable form, but it should do the trick.
Thanks much for taking time to respond to an OT question.
digger
| [reply] |