Red Virus
Red Virus

Reputation: 1707

MySQL WHERE IN Returns only 1 record

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) enter image description here

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'

enter image description here

Upvotes: 0

Views: 84

Answers (1)

Ashish Gondaliya
Ashish Gondaliya

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

Related Questions