I have a table like this:
UID(int) NUMBERS(blob) ---------------------- 1 1,13,15,20 2 3,10,15,20 3 3,15
And I would like to test if 3 and 15 are in the blob called NUMBERS. And can see the LIKE %% cannot be used
Only row with ID 2 and three scoulb be selected...
MySQL has an inbuilt function called FIND_IN_SET which will search for values within a comma separated values. It basically returns the index position of the first parameter within the second parameter. This can be alternatively used to replace the IN clause. WHERE FIND_IN_SET (item_description,'Mobile,laptop');
To check if value exists in a comma separated list, you can use FIND_IN_SET() function. Now you can insert some records in the table using insert command. Display all records from the table using select statement.
A better answer: Don't store a list of comma separated values. Store one value per row, and use a SELECT query with GROUP_CONCAT to generate the comma separated value when you access the database.
This one also works:
SELECT * FROM table WHERE 3 IN (NUMBERS) AND 15 IN (NUMBERS)
using the IN will look into a comma separated string eg. these two
WHERE banana IN ('apple', 'banana', 'coconut') WHERE 3 IN (2,3,6,8,90)
Info found on this page:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With