In MySQL table, I have a field called “Tag”, which may include multiple comma-delimited values.
I want to select rows where the Tag field contain the value of “1”.
How would I write my MySQL statement so I select rows with Tag values of “1” and “1,Cars”,
but exclude the rows with Tag values of “17” and “17,Cars”?
The problem that I’m using the “LIKE” operator, but that causes all four of these rows to be selected.
Thanks.
FIND_IN_SET will search a comma-separated list, e.g.:
In this case, something along the lines of
should do the trick.
EDIT: It actually returns 0 when no match is found, so the NULL check was wrong.