-1

If I have table like this

+------+---------------------------+
|  Id  |  City                     |
+------+---------------------------+
|   1  | Vancouver, Miami, New York| 
+------+---------------------------+
|   2  | Vancouver Miami           | 
+------+---------------------------+
|   3  | New York                  | 
+------+---------------------------+
|   4  | Miami                     | 
+------+---------------------------+
|   5  | Vancouver, New York       | 
+------+---------------------------+
|   6  | New York Miami            | 
+------+---------------------------+
|   7  | Vancouver                 | 
+------+---------------------------+

And some user want get data from Miami or Vancouver

How to write query to get data with id 1,2,4,5,6,7

Data with id 3 should not be displayed because there is no Miami or Vancouver in that string

EDIT: Because I am getting Miami and Vancouver in array list I need query using function WHERE IN ()

Ante Ereš
  • 623
  • 4
  • 8
  • 24

1 Answers1

1

There are two ways of doing this, both of them don't involve using WHERE IN approach, it's not possible to use wild card matching on multiple values with IN operator.

  1. Use OR statement

    SELECT * FROM yourtable WHERE CITY LIKE '%Miami%' OR CITY LIKE '%Vancouver%'

  2. Using REGEXP for Mysql5.0 and above

    SELECT * FROM yourtable WHERE CITY REGEXP 'Miami|Vancouver'

Pankaj Gadge
  • 2,748
  • 3
  • 18
  • 25