I have a value "Berlin, Paris, London, ..." and I Want to do an MySQL Query
SELECT * FROM restaurants
WHERE restaurant_city LIKE '%array%';
To get all restaurants where the city contains EITHER Berlin OR Paris OR London
How can I realize that?
I have a value "Berlin, Paris, London, ..." and I Want to do an MySQL Query
SELECT * FROM restaurants
WHERE restaurant_city LIKE '%array%';
To get all restaurants where the city contains EITHER Berlin OR Paris OR London
How can I realize that?
If in mysql we can do
SELECT * from restaurants where restaurant_city REGEXP 'Berlin|Paris|London';
Implode the given array using '|' and then use this generated string in query (In php).
$comma_separated = implode("|", $array);
Use the comma separated string in query
mysqli, Can we use mysqli without PHP ?Do a reverse trick.
SELECT * FROM restaurants WHERE 'array' LIKE concat('%',restaurant_city,'%')
So the query will be like:
SELECT * FROM Table1 WHERE 'Berlin, Paris, London' LIKE concat('%',restaurant_city,'%')
Sample in SQL Fiddle
Try it-
SELECT * FROM restaurants
WHERE find_in_set (restaurant_city,'Berlin,Paris,London');