Reputation: 1707
I' am storing the profile friends ID in a string format comma delimited. When the run the Query, its gives 1 record whereas it should return with 2 records.
MySQL Query
SELECT * FROM PROFILES WHERE profile_id IN(SELECT profile_friends FROM PROFILES WHERE profile_id = '1')
Which gives this result (The results should be 2 records NOT 1 Record)
When I run the following Query, gives me two ID's that are in a profile_friends field.
SELECT profile_friends FROM PROFILES WHERE profile_id = '1'
Upvotes: 0
Views: 84
Reputation: 318
Please use following Query
SELECT * FROM PROFILES WHERE FIND_IN_SET(profile_id,(SELECT profile_friends FROM PROFILES WHERE profile_id = '1'))
IN clause only use when you search value from integer field
But your field(profile_friends) is string so following clause you need to use.
FIND_IN_SET
Upvotes: 2