Selecting with a list of keys

2005-02-23 Thread Tim Johnson
I would like to construct a query that searces on a variable list of  
primary keys.
Example: Lkeys = [12, 23, 15, 17]## python - style list of integers
Select column from table where ID in Lkeys;  ## mysql statement?

Is this possible, or does one have to generate a query for each key or 
generate
a query with multiple ORs?

This will have to be run on a *nix server with version prior to 4.0, I 
believe.
Solutions, comments and pointers to relevant documentation is all welcome.

Thanks
Tim Johnson
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]


Re: Selecting with a list of keys

2005-02-23 Thread Roger Baklund
Tim Johnson wrote:
I would like to construct a query that searces on a variable list of  
primary keys.
Example: Lkeys = [12, 23, 15, 17]## python - style list of integers
Select column from table where ID in Lkeys;  ## mysql statement?

Is this possible, or does one have to generate a query for each key or 
generate a query with multiple ORs?
MySQL supports the IN operator, you can write:
Select column from table where ID in (12, 23, 15, 17)
In Python this could be done like this:
Lkeys = [12, 23, 15, 17]
res = query('Select column from table where ID in (%s)' %
  (','.join(map(str,Lkeys
--
Roger
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]