Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7574891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:32:53+00:00 2026-05-30T16:32:53+00:00

Is it possible to JOIN in a query and use a NOT IN() clause?

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T16:32:54+00:00Added an answer on May 30, 2026 at 4:32 pm

    How about doing an outer join and only selecting those rows where c.mID is null?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this hql query, which works perfect: select m from Media m join
Is it possible to do a join to a nested select statement in SubSonic
Possible Duplicate: What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN
Possible Duplicate: Why not use tables for layout in HTML? Under what conditions should
I have a base query made (Thanks Justin Cave!) Now I have to use
I've got a query that calls a function in its select clause. The function
I have this query: SELECT p.text,se.name,s.sub_name,SUM((p.volume / (SELECT SUM(p.volume) FROM phrase p WHERE p.volume
I'm having trouble optimizing this query: SELECT a.id FROM a JOIN b ON a.id=b.id
Is it possible to write a sql query where you know you have to
Let us say I have a query like this: SELECT * FROM ( SELECT

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.