How do you find a number (e.g., "8") in a CSV string in a MySQL field without finding numbers that contain that number (e.g., "18" or "81")?
For example:
- csvString1 in
somecolumn
=8,14,18
- csvString2 in
somecolumn
=4,5,8,13
- csvString2 in
somecolumn
=18,81,82,88
I need to have #1 and #2 come up true
and #3 come up false
. How do I do that
SELECT *
FROM sometable
WHERE s开发者_开发知识库omecolumn REGEXP '(what here?)';
use find_in_set
select find_in_set('8', '18,81,82,88');
--> zero
select find_in_set('8', '8,14,18');
--> 1
select find_in_set('8', '4,5,8,13');
--> 3
So,
select * from your_table
where find_in_set('8', your_col)<>0;
PS: normalize your data to avoid future problem
精彩评论