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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:37:17+00:00 2026-05-27T02:37:17+00:00

I’m struggling with 3 tables I’m trying to join and exclude certain results. Basically

  • 0

I’m struggling with 3 tables I’m trying to join and exclude certain results.
Basically it’s almost the same as mysql join where not exists, however I still can’t figure out how to combine multiple tables successfully.

The goal is to select results from table A where the row in the intermediate table B is null OR where the table C (linked to B, but not to A) does not match a specific value.

Something like:

SELECT      x 
FROM        tablea
LEFT JOIN   tableb
ON          tablea.x = tableb.x
LEFT JOIN   tablec
ON          tableb.y = tablec.y
WHERE       tableb.x IS NULL
OR          tablec.z != 'excluded'

but it doesn’t work.
I’d also like to avoid subqueries like using NOT IN or NOT EXISTS in order to speed up things… any suggestions?

EDIT: in spite of what I previously said, it should work. Just remember to double check proper braces, nesting and the ‘where’ clauses position when merging multiple joins

  • 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-27T02:37:17+00:00Added an answer on May 27, 2026 at 2:37 am

    This should do the trick with one query and be reasonably fast. 🙂

    SELECT x 
    FROM tablea
        LEFT JOIN tableb ON tablea.x = tableb.x
        LEFT JOIN tablec ON tableb.y = tablec.y AND tablec.z != 'excluded'
    WHERE
        tableb.x IS NULL
        OR tablec.y IS NOT NULL
    

    This is under the assumption that you don’t mind getting rows from tablea where both tableb.x is null and tablec.y is null, or that neither of them are. If you want only rows from tablea where tableb.x OR tablec.y contains values, you need to change the OR to XOR.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
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
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I need a function that will clean a strings' special characters. I do NOT
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post

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.