Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: how do i construct a sql select statement, where i want to get the where clauses out of an array

by thpfft (Chaplain)
on Aug 25, 2001 at 21:11 UTC ( [id://107843]=note: print w/replies, xml ) Need Help??


in reply to how do i construct a sql select statement, where i want to get the where clauses out of an array

mysql supports the IN() clause. So it might be easiest to use this:

SELECT id, size FROM table WHERE id IN ('$id[0]', '$id[1]', ...)

Which i would build this way, but there are plenty of others:

my $idlist = join(',', map($dbh->quote($_),@id)); $statement = "SELECT id, size FROM table WHERE id IN ($idlist)";

Apparently there are issues with the length of @id: past a certain point it would need to be divided into chunks for this approach to work.

update *sigh*. redundant again.

  • Comment on Re: how do i construct a sql select statement, where i want to get the where clauses out of an array
  • Select or Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2024-04-19 13:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found