I am trying to get the users I am not following and that isn't equal to me.
So far I have got this query:
FROM USERS u
JOIN Activity a
WHERE NOT u.id = 145
AND a.id = 145
AND type = 'follow'
There are various ways to accomplish the expected outcome. They are all based on using a subquery to determine if a user is followed by a given user. You can have this subquery as a derived table (in the
from clause), or in a
not in() or not exists() operator. I'll show you an example for the
not exists() operator because it does not have to pull data from the users table, it merely checks if you have a record corresponding to the where criteria
select * from users u1 where u1.id<>145 --not me and not exists (select 1 from activity a where a.id=145 --users I follow and a.IdOtherUser=u1.id and a.type='follow')