0

I have one column that have data value 49,22 Now running below query. it is not returning any result.

SELECT * FROM `tablename` WHERE 22 IN column_name

what could be problem?

nitin jain
  • 298
  • 6
  • 19

2 Answers2

2

Thats a bad DB design and you should never store comma-separated values, and normalize the table, however in this case you need to use find_in_set function as

select * FROM `tablename`
where find_in_set(22,column_name) > 0 
Abhik Chakraborty
  • 44,654
  • 6
  • 52
  • 63
0

If you want to check multiple rows if they contain 22 or 49, you can use the IN syntax:

SELECT * FROM `tablename` WHERE column_name IN(22,49)

If you just want to check if 22 is in a string which is 49,22 then use this:

SELECT * FROM `tablename` WHERE column_name LIKE '%22%'

Your question is in this point a bit unclear. :-)

Ionic
  • 3,884
  • 1
  • 12
  • 33