Hi,
I'm building out a social network system, and when trying to pull user info for a user's friends, I'm stumbling into a problem with the query. The issue is I'm trying to keep the lookup table from listing redundant entries. For instance,
FRIENDS TABLE
-------------
uid | fid
-------------
1 | 2
2 | 1
That's what I'm trying to avoid, so I want the query to look for the user's id in either the uid field and return the fid or find it in the fid and return the uid. Here's what I have. I've tried a bunch of different things, but so far nothing's worked.
SELECT username FROM users WHERE id = (SELECT fid as id FROM friends WHERE uid = {$this->id}) OR (SELECT uid as id FROM friends WHERE fid = {$this->id})
Is there any way to do this or do I need to just use redundant listings in my lookup table?