Maybe answer is very easy, but I can't find the right MySQL query which do what I want.
I have table user :
| id_user | name | action_type |
+---------------------------------+
| 1 | joshua | 1,13,12,40 |
| 2 | joshua | 2,8 |
And I want to select only rows which have exact number in action_type
column.
action_type
is stored in MySQL as TEXT.
I've tried this:
SELECT * FROM user WHERE action_type LIKE '%2%'
But it selected rows with 12 which is not what I want :(
Maybe it's possible with IN operator, but I couldn't find a right way to use this.
You are looking for
FIND_IN_SET
SQL Fiddle DEMO
UPDATE
Just to mentioned it, this is also possible
MySQL will do an automatic conversion to char
Try
Include the delimiter in your
LIKE
clause:Note that I had to use two additional
LIKE
clauses to cover the cases where the item is at the beginning or end of the string.