I have a table name messages. There is a column name receiver_id
I need to fetch record where receiver_id = 4 but i am always getting null output.<
This should also work (SQL Fiddle):
SELECT *
FROM messages
WHERE receiver_id LIKE '%,4,%'
OR receiver_id LIKE '4,%'
OR receiver_id LIKE '%,4'
OR receiver_id = '4'
Or with regex (SQL Fiddle):
SELECT *
FROM messages
WHERE receiver_id REGEXP '4,|,4,|,4'
OR receiver_id = '4'
Storing comma separated values is really a bad design you should normalize it first by storing all association of receiver in a junction table,If you are not able to alter your schema then for your current situation you can use find_in_set() to search values in a comma separated list
select * from table
where find_in_set(4,receiver_id ) >0