On 12/7/05, Sean Davis <[EMAIL PROTECTED]> wrote:
> Select id from table where name in ('q','w');

Yes, that will technically work. However, how does your solution tell
me which id corresponds to q and which to w?

Much better would be:
SELECT name, id
  FROM table
 WHERE name IN ( 'q', 'w' )

The Perl for this could look something like:

sub get_name_ids {
    my @names = @_;

    my $sql = 'SELECT name, id FROM table WHERE name IN (';
    $sql .= join( ',', ('?') x @names );
    $sql .= ')';

    my $sth = $dbh->prepare( $sql );
    $sth->execute( @names );

    my $results = $sth->fetchall_hashref;

    return $results;
}

This will return something that looks like:
$results = [
    { id => 3, name => 'w' },
    { id => 5, name => 'q' },
];

Rob

---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/[email protected]/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to