Reputation: 1499
I have a many to many table which keeps track of friendship.
I need to know that both friends approved each other.
For example, when a person asks to be a friend, their id gets put in self_uuid and the friends in friend_uuid. When the friend approves the request the same thing happens, just the other way around.
how do find all people that have mutually approved each other? how do i find all the people that have NOT mutually approved each other?
Upvotes: 0
Views: 134
Reputation: 780842
Mutual approval:
select f1.self_uuid, f1.friend_uuid
from friends f1
join friends f2 on f1.self_uuid = f2.friend_uuid and f1.friend_uuid = f2.self_uuid
Friend requests that have not been approved:
select f1.self_uuid, f1.friend_uuid
from friends f1
left join friends f2 on f1.self_uuid = f2.friend_uuid and f1.friend_uuid = f2.self_uuid
where f2.self_uuid is null
Upvotes: 3