PDA

View Full Version : Multiple Selections in SQL query


AndyST
02-05-2012, 02:29 PM
I have a MYSQL database where visitors can select cities that they will be traveling to in the near future.
They can name up to 7 cities. I take their list of cities and then query a table where local hotels are available nearby.

My question: Is there an easy way to name a group of cities and then do an sql query for any city in that group.

For example table MyCities = {'New York', 'Chicago', 'Denver', 'LA', 'Mia' };

And I would like to say something like this:

SELECT * from MyCities WHERE city IS .... MyCities;


Is this possible, or do I have to do the long form:

SELECT * from MyCities WHERE city='New York', 'Chicago', 'Denver' 'LA' OR city='LA';


Looking for the proper way to execute this.

thanks

Sandman
02-05-2012, 02:46 PM
Try using IN

WHERE city IN ('New York','Chicago','Denver','LA', 'Mia')

:D