Search code examples
mysqlsql-likesql-in

MySQL like with IN clause


Is it possible to extend a LIKE expression with an IN clause?

At the moment I got the following SQL:

select * 
from SECURITY_PERMISSION permission
where permission.PERMISSION_ID like '%_10498_%'
and permission.PERMISSION_ID like '%_OBJ_VIEW%'

I want to pass a list of Numbers to my like expression. Something like that:

select * 
from SECURITY_PERMISSION permission
where permission.PERMISSION_ID like '%_IN(list_of_numbers)_%'
and permission.PERMISSION_ID like '%_OBJ_VIEW%'

Solution

  • That is bad database design. But you can use REGEXP instead:

    WHERE permission.PERMISSION_ID REGEXP '_(123|456|789)_'
    

    It is still bad database design.