Skip to content
Advertisement

select in column that has array(value1,value2,…) in sql table [closed]

I have a sql table called “users”

inside this table a column named “Cities” has array in it (1,2, 3,…)

row1 :”1,2,15,69,98″

row2 :”7,9,15,5,69″

row3 :”7,3,1,5,6″

how can I select rows which has multiple value in same time

for exp : I want to select rows which has 1 in it

the result should display row1 and row3 .

Advertisement

Answer

Use FIND_IN_SET:

SELECT *
FROM users
WHERE FIND_IN_SET('1', Cities) > 0

As others have mentioned, storing CSV data in your users table is sub-optimal because it undermines much of the relational power which the database has. But if you have to proceed as is, FIND_IN_SET might let you do that.

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