Skip to content
Advertisement

mysql statmet that match exaxct “1” using regex

I want to create a regex to find a single 1 from the flowing

the following list is the sample of the column value I like to search in

  • 1,2
  • 2,1
  • 3,1,2
  • 7,171,818
  • 71,17,11
  • 1

Note: the needed match is bolded in the prev list

Advertisement

Answer

You can go with either approach …

SELECT data FROM SAMPLE
WHERE data REGEXP '^1,|,1$|,1,|^1$'

enter image description here

SELECT * 
FROM sample
WHERE 
(data LIKE '1,%'
 OR
data LIKE '%,1'
 OR
data LIKE '%,1,%'
 OR
data LIKE '1')

enter image description here

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement