Reputation: 13
I have several comma delimited lists of numbers. I need to match specific lines with a sql query. I want to build correct RegExp for this and i need your help.
Example of my rows with comma delimited lists of numbers :
I need to match lines that contain only numbers 8 and 44
My sql query looks like this :
SELECT id FROM my_list WHERE id_list REGEXP '^[0-9,]8,[0-9,]44[0-9,]$'
Thanks in advance !
Upvotes: 1
Views: 67
Reputation: 160833
Use FIND_IN_SET Function:
SELECT id FROM my_list WHERE FIND_IN_SET('8', id_list) AND FIND_IN_SET('44', id_list)
Upvotes: 1
Reputation: 1949
Try this:
SELECT id FROM my_list WHERE CONCAT(",",id_list,",") REGEXP ',8,|,44,'
Upvotes: 0