I am trying to find all occurrences of a string in a field using the IN command but not returning any results when I know there should be some.
I think the best way to show you is by example:
mysql> SELECT detail_sections FROM inet_staff_details WHERE detail_sections !='';
+-----------------+
| detail_sections |
+-----------------+
| 10,11 |
| 10,11 |
| 10,11 |
| 10,11 |
+-----------------+
4 rows in set (0.00 sec)
mysql> SELECT * FROM inet_staff_details WHERE 11 IN (detail_sections);
Empty set, 4 warnings (0.00 sec)
mysql> SELECT * FROM inet_staff_details WHERE '11' IN (detail_sections);
Empty set (0.00 sec)
As you can see, the number 11 is in the comma separated list but does not show up in the results. Please can you advise what I am doing wrong?
Cheers.
Try this query –
FIND_IN_SET function.