user3497051
user3497051

Reputation: 13

Function REGEXP with a list of numbers

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

Answers (2)

xdazz
xdazz

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

blue
blue

Reputation: 1949

Try this:

SELECT id FROM my_list WHERE CONCAT(",",id_list,",") REGEXP ',8,|,44,'

Upvotes: 0

Related Questions