Issue
I have a Mysql database that contains some category ids on it which stores comma-separated values on a table.
By using select * from style where categories like '%8,%';
it returns all the values end with 8. For example, if the table rows have two values like 8 and 148 it returns both rows. But I want to get only the rows that contain 8. How to do it
Solution
Storing multiple values in a single column is a denormalised design that will almost always cause you problems. However you need to add commas to both sides and compare:
select *
from Style
where concat(',',Categories,',') like '%,8,%';
Answered By – Stu
Answer Checked By – Katrina (BugsFixing Volunteer)