Tuesday 28 August 2018

Mysql - IN () Function does not return results using a percent sign

It's short and simple.

I'm using this query:
SELECT * FROM TABLE_NAME WHERE COL_NAME IN('%VALUE1%', '%VALUE2%')

However it doesn't seem to work, I've used LIKE for both values combined using ORand it returns results, so I'm certain that there's rows in the table with these values.. am I missing something here?
Does MYSQL IN() function accept percentage sign? What is the right way to do it?
Thanks in advance!

You could try with RLIKE:
SELECT * FROM TABLE_NAME WHERE COL_NAME RLIKE 'VALUE[12]'

Keep in mind these sorts of queries tend to perform very badly because they require a full table scan. If you're doing this a lot you may want to adjust your schema to better represent your usage patterns.

0 comments:

Post a Comment