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 8969157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:33:12+00:00 2026-06-15T17:33:12+00:00

I’m confused as to why this is not working, I’ve used this type of

  • 0

I’m confused as to why this is not working, I’ve used this type of syntax several times but this one as got me pulling my hair out.

I have two tables;

tableA

regId name    regStatus
1     George  1
2     Jenny   1
3     Penny   1
4     James   1
5     Preston 1
6     Jamie   0

TableB

activeRegId passiveRegID Status
1            2           1
1            3           1
1            4           0
6            1           1

What I’m trying to do is return all rows from tableA excluding those where (tableA.regstatus = 0) and (tableB.status = 1 for a user regid = 1).

I want to avoid having to use NOT IN (select ...).

My query so far:

    select top 10 
        tA.regId, tA.name
    from 
        tableA tA 
    left OUTER JOIN 
        tableB tB ON tB.activeRegId = tA.regid AND tB.passiveRegID <> 1 
                     AND tB.status <> 1 AND tB.passiveRegID IS NULL
    where 
        tA.regStatus = 1
        and tA.regid <> 1

What I’m expecting back should be as follows however, I’m getting all the users in tableA except for Jamie.

regId name
4     James
5     Preston
  • 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-06-15T17:33:13+00:00Added an answer on June 15, 2026 at 5:33 pm

    I think you need to move some of the predicates out of the ON clause of the LEFT OUTER JOIN, and instead have them as predicates in the WHERE clause.

    Based on the data you provided, I can’t be sure exactly what the predicates should be, however any predicates you include in the ON clause of a LEFT OUTER JOIN only serve to exclude rows from Table B, not Table A.

    With a LEFT OUTER JOIN, you will still get all records of Table A unless they are excluded by predicates in the WHERE clause.

    EDIT
    Based on comments, I think this would work, where ‘loggedInUserId’ is the regId from Table A of the logged in user:

    SELECT top 10
       tA.regId,
       tA.name
    FROM tableA tA1
    JOIN tableA tA2
    ON (tA1.regId <> tA2.regId
        AND tA2.regStatus <> 0)
    LEFT OUTER JOIN tableB tB
    ON (tA1.regId = tB.activeRegId
        AND tA2.regId = tB.passiveRegID
        AND tB.Status <> 0)
    WHERE tA1.regId = 'loggedInUserId'
    AND tB.activeRegId IS NULL
    

    To also exclude those who have blocked the logged in user:

    SELECT top 10
       tA.regId,
       tA.name
    FROM tableA tA1
    JOIN tableA tA2
    ON (tA1.regId <> tA2.regId
        AND tA2.regStatus <> 0)
    LEFT OUTER JOIN tableB tB
    ON (
        --finding blocked users
        (tA1.regId = tB.activeRegId
         AND tA2.regId = tB.passiveRegID
         AND tB.Status <> 0)
        OR
        --finding blocking users
        (tA2.regId = tB.activeRegId
         AND tA1.regId = tB.passiveRegId
         AND tB.Status <> 0)
        )
    WHERE tA1.regId = 'loggedInUserId'
    AND tB.activeRegId IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm not entirely sure how I managed to jack this up. http://pretty-senshi.com If you
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I've got a string that has curly quotes in it. I'd like to replace
this is what i have right now Drawing an RSS feed into the php,

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.