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
  • 300
  • 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
  • 43,914
  • 5
  • 48
  • 61
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,834
  • 1
  • 10
  • 33