Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Slightly OT - SQL Question

by simonm (Vicar)
on Sep 20, 2003 at 20:23 UTC ( [id://292906]=note: print w/replies, xml ) Need Help??


in reply to Slightly OT - SQL Question

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.

Replies are listed 'Best First'.
Re: Re: Slightly OT - SQL Question
by digger (Friar) on Sep 20, 2003 at 22:39 UTC
    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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://292906]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (7)
As of 2024-04-25 11:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found