7 messages in com.mysql.lists.mysqlRe: Change from loop to single query
FromSent OnAttachments
Jonathan Villa02 Jan 2004 09:17 
John McCaskey02 Jan 2004 09:26 
Tobias Asplund02 Jan 2004 09:32 
Douglas Sims02 Jan 2004 09:39 
Jeremy March02 Jan 2004 09:40 
Jonathan Villa02 Jan 2004 11:22 
Bob Terrell02 Jan 2004 15:59 
Subject:Re: Change from loop to single query
From:Douglas Sims (DSi@Apley.com)
Date:01/02/2004 09:39:48 AM
List:com.mysql.lists.mysql

You probably want the IN comparison operator (http://www.mysql.com/doc/en/Comparison_Operators.html)

For example:

UPDATE users SET status=no WHERE name IN ('Joe', 'Wally', 'Bob', 'Cynthia');

Of course, you can create this statement from the list of names by joining all of the names with commas.

Good luck!

Jonathan Villa wrote:

I have a loop which is similar to the following:

while(array contains elements) { UPDATE users SET status = no WHERE name = array[i] } great, it works but the query runs many times. I want to make only one call to the database and have all the elements in the array be included in the query