Skip to content
Advertisement

Query condition where a value is in a comma separated string

I have a table in which one of the table columns third_row stores a comma-separated list of numbers as a string but when its value is A then it means a combination of all the possible numbers. How do I approach this so that the query returns all the rows that have the third_row as A and the rest where third_row is equal to one of the values in the comma-separated string?

For reference, here is the format of the table:

first_row second_row third_row
0028001070200 50 A
0049048000701 51 01,04,02,31,

I have also tried this query but no luck:

Advertisement

Answer

Your method almost works:

You can also use string matching:

Or you could convert to an array and use array operations.

I would strongly suggest that find a representation other than strings for storing integer values — preferably another table or perhaps an array.

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