Skip to content
Advertisement

mysql query: pull all rows where field2 has 01, 02, or 04 as any part of it

I have a query:

The goal is to pull all rows where field2 has 01, 02, or 04 as any part of it. field2 typically has comma separated values like 01,02,03 or sometimes just a single 02. However, when I run this query, I get back only one result that has 01,02,03,04 as the value, and it isn’t the only one in the table with that exact same data.

This is essentially what the table looks like:

|id|field1  |field2             
| 1| NULL|01,02,03,04
| 2| NULL|01,02,03,04
| 3| NULL|01,02,04

Advertisement

Answer

You can use REGEXP function:

e.g:

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