I have this MySQL query.
I have database fields with this contents
sports,shopping,pool,pc,games
shopping,pool,pc,games
sports,pub,swimming, pool, pc, games
Why does this like query does not work? I need the fields with either sports or pub or both?
SELECT * FROM table WHERE interests LIKE ('%sports%', '%pub%')
The
(a,b,c)
list only works within
. Forlike
, you have to useor
:Don't forget to use parenthesis if you use this function after an
AND
parameterLike this:
Like @Alexis Dufrenoy proposed, the query could be:
More information in the manual.
Why not you try REGEXP. Try it like this:
You can also use
RLIKE
as well.For example:
Or if you need to match only the beginning of words:
you can use the regexp caret matches:
https://www.regular-expressions.info/anchors.html