I have a need to find a particular number from a column, say I look for number 9
in table tours
which has a column city
. The column city
has a string of numbers like
9
49
5,9
4,94
5,8,89,32
and I need to find the number 9 in these so the only results I would want would be
9
5,9
I have tried using REGEX but can't get it right. Can anyone point me to the right direction? Here's the query so far
SELECT
a.title, a.tourprice, a.city, b.city AS destCity
FROM
tours a
RIGHT JOIN
(SELECT
id, city
FROM
destinations
WHERE
id = 47) b ON a.city LIKE CONCAT('%,', b.city) OR a.city LIKE CONCAT(b.city, ',%') //b.city evaluates to 9
I realize there may or may not always be a comma before or after the number I want.