Select a field with specific data between commas by regular expression

I have a table in MySQL with this data in it

enter image description here

I want to get rows with "1" in column row1 using regex. How can I do it?

([^,]1/) 

I use this regex, but it only returns rows with "1" in the first comma

+5
source share
2 answers

You can use the FIND_IN_SET () mysql function

 select * from my_table where FIND_IN_SET('1',row1) > 0 
+4
source

Try:

 select * from tbl where row1 REGEXP '(^|,)1(,|$)' 

(^|,)1(,|$) means (either begenning , or , ) 1 (either begenning or end )

sql script demonstration

+2
source

Source: https://habr.com/ru/post/1238068/


All Articles