0

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:

  1. csvString1 in somecolumn = 8,14,18
  2. csvString2 in somecolumn = 4,5,8,13
  3. 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 somecolumn REGEXP '(what here?)';

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

same as not equal (not smaller than, and not greater than)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.