Reputation: 129
First this is how my table looks like:
tbl
------------------------------------------
| USERID | requestID
|[email protected] | [email protected]
|[email protected] | [email protected]
|[email protected] | [email protected]
|[email protected] | [email protected]
|[email protected] | [email protected]
|[email protected] | [email protected]
I named my columns wrong but userIds are the ids that are following requestIds, and requestIds are the ids that are being followed.
What I want to do is to find the cases that the ids are following each other.
Like for example, I log in with the id [email protected](this is not real address), then I find ids that I'm following and also the ids that follows me, but under the ids that are following each other, I want to print out some text saying that they are following each other. (So under test1 and test2, I should have that text.)
I found this but this does not really apply to my situation as I have to get the results under one logged in ID.
I was trying to do this by myself but I'm all out of ideas. Please help me out. Thanks in advance.
Upvotes: 0
Views: 4154
Reputation: 805
You will have to join the table with itself and compare. So something like
SELECT *
FROM table as t1
JOIN table as t2
ON t1.requestid = t2.useriD and t1.userid = t2.requestid
Upvotes: 2