Select Row Which Contains Exact Number In Column With Set Of Numbers Separated By Comma
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 | +---------------------------------+
Solution 1:
You are looking for FIND_IN_SET
SELECT*FROMuserWHERE FIND_IN_SET( '2', action_type )
UPDATE
Just to mentioned it, this is also possible
SELECT*FROMuserWHERE FIND_IN_SET( 2, action_type )
MySQL will do an automatic conversion to char
Solution 2:
Include the delimiter in your LIKE clause:
SELECT*FROMuserWHERE action_type LIKE'2,%'OR action_type LIKE'%,2,%'OR action_type LIKE'%,2'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.
Solution 3:
Try
SELECT*FROMuserWHERE CONCAT( ',', action_type, ',' ) LIKE'%,2,%';
- correct syntax from Sir Rufo
Post a Comment for "Select Row Which Contains Exact Number In Column With Set Of Numbers Separated By Comma"