I have a table that uses a SET datatype for one of the fields, and to check if the field contains a specific element I use
SELECT * FROM table WHERE myset LIKE %value%;
This works most of the time, but two of the potential values have the same word, i.e. one possible element in the set is Poodle and another is Toy Poodle. If I do
SELECT * FROM table WHERE myset LIKE %Poodle%;
It returns all rows that have either Poodle or Toy Poodle. I want it to only return if the field contains Poodle. If I remove the wildcards then it will only return the rows that have ONLY Poodle. So basically, if the table was:
id | myset
-------------------------
1 | "Poodle"
2 | "Toy Poodle"
3 | "Poodle","Toy Poodle"
4 | "Toy Poodle","Poodle"
I need a select statement that would return 1,3, and 4 but not 2. Is this possible?
You need to do: SELECT * FROM table WHERE FIND_IN_SET('Poodle',myset)>0
as described in documentation
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