query optimization
- by Gaurav
I have a query of the form
SELECT uid1,uid2 FROM friend WHERE uid1 IN (SELECT uid2 FROM friend WHERE uid1='.$user_id.') and uid2 IN (SELECT uid2 FROM friend WHERE uid1='.$user_id.')
The problem now is that the nested query
SELECT uid2 FROM friend WHERE uid1='.$user_id.'
returns a very large number of ids(approx. 5000).
The table structure of the friend table is uid1(int), uid2(int). This table is used to determine whether two users are linked together as friends.
Any workaround? Can I write the query in a different way? Or is there some other way to solve this issue. I'm sure I am not the first person to face such a problem.
Any help would be greatly appreciated.