Reputation: 36937
Is it possible to JOIN in a query and use a NOT IN() clause?
What I have is
SELECT DISTINCT loc.*,
a.firstname,
a.lastname,
a.profileimg,
(((acos(sin((37.2790669*pi()/180)) * sin((`latitude`*pi()/180))+cos((37.2790669*pi()/180)) * cos((`latitude`*pi()/180)) * cos(((-121.874722 - `longitude`)*pi()/180))))*180/pi())*60*1.1515) AS `distance` FROM memb_geo_locations loc
JOIN memb_baseInfo a ON a.mID = loc.mID
JOIN memb_friends c ON (c.mID = loc.mID OR c.friendID = loc.mID) AND (c.mID = 21 OR c.friendID = 21)
WHERE loc.primaryAddress = '1'
AND loc.mID NOT IN(21)
HAVING `distance` < 25 ORDER BY `distance` ASC LIMIT 0, 25
I need this line
JOIN memb_friends c ON (c.mID = loc.mID OR c.friendID = loc.mID) AND (c.mID = 21 OR c.friendID = 21)
to act as a NOT IN() cause I am trying to exclude people from the results that are "friends" on the memb_friends table both column mID and friendID are in a sense the same number. Dependant upon who initiated the request for a friendship. So lets say my ID is 21 I can either be the friendID or the mID on that table and someone else's ID is the counterpart. I have 10 friends on my list lets say, and 1000 people in my database. So the conclusion should be I have 990 results to work with after the query is done, but Im stuck on this one, either how to JOIN the table in for use with the query and then how to exclude from there.
Upvotes: 0
Views: 58
Reputation: 6817
How about doing an outer join and only selecting those rows where c.mID is null?
Upvotes: 1