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

  • Home
  • SEARCH
  • 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 7018091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:59:55+00:00 2026-05-27T22:59:55+00:00

I have 3 tables A, B and T T holds a foreign key to

  • 0

I have 3 tables A, B and T

T holds a foreign key to table A and B respectively.

Now I would like to get all rows of (A,B,T) even if T is empty.

SELECT * from

A
LEFT OUTER JOIN T t1 ON t1.A_ID = A.id,
B
LEFT OUTER JOIN T t2 ON t2.B_ID = B.id

WHERE A.B_ID = B.ID

Now the problem is that I get too many rows so I add the following:

AND t1.id = t2.id

But now I get no rows at all which I tried to avoid in the first place via including the LEFT OUTER JOIN.

EDIT: Apart from any sample-data or table-layout my question is merely if a table T with foreign-key-dependencies to more than ONE table in this case A + B needs 2 left-outer-joins as given above or maybe there is another way?

Simply refering to table A in the second left-join like some users suggested cannot work as it is out-of-scope, also explained
here
So it works if you surround both tables with parens:

SELECT * from (A, B)
LEFT OUTER JOIN T t ON t.A_ID = A.id and t.B_ID = B.id
  • 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-27T22:59:56+00:00Added an answer on May 27, 2026 at 10:59 pm

    Try this query:
    If A and B no any relation:

    SELECT * FROM
    (A, B)
    LEFT OUTER JOIN T ON T.A_ID = A.id
    AND T.B_ID = B.id
    

    And if A and B have relation add this line at last:

    WHERE A.B_ID = B.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables with the following (simplified) structures: table "Factors" which holds data
i have a table that holds my users information like username , password ,
I have a monthly table (only holds rows with first day of month, and
I have a base table called users which holds all common information about a
Suppose we have a table which holds information about person. Columns like NAME or
i want to do for a table something like this. I have two tables
I have a table RecentChanges which holds reference to all actions done on my
I have 2 tables: 1st holds employees (of ones in any position) and the
i have two tables one is called addons and holds information about different addons,
I have three tables: upload, tag and upload_tag. Upload holds details of a file

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.