Update: I figured it out. See my answer below.
I’m trying to write some logic at the application level to identify the friends (mutual followers)in the table below. My query has returned the data in a format similar to the table below (borrowed from this question, but I don’t need a query, that part’s done):
A B
1 2 // mutual followers, so "friends"
2 1 // mutual followers, so "friends"
1 3 // user 1 is following 3
1 4 // user 1 is following 4
So how can I write some logic which shows the users where A = B and B = A, but in different rows? Using PHP/codeigniter.
In response to a request, here’s the SQL tables and query:
Users table - uid, fname, lname
Followers table - user_id, follow_id
Select users.uid, users.fname, users.lname, u.uid, u.fname, u.lname
FROM users
INNER JOIN follows f on (f.user_id=users.uid)
INNER JOIN users u on (u.uid=f.follow_id)
Okay, I figured it out. I needed a second INNER JOIN for the followers table. I added the code below to my SQL query, and it worked.