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

The Archive Base Latest Questions

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

I need to join 4 tables based on a common primary key. If sqlite

  • 0

I need to join 4 tables based on a common primary key. If sqlite implemented full outer joins it might look something like this (with optimization not taken into account).

SELECT S.pair, C.ball, P.bluejeans, B.checkered 
FROM Socks S 
FULL OUTER JOIN Caps C 
FULL OUTER JOIN Pants P 
FULL OUTER JOIN Boxers B 
WHERE S.color = C.color AND S.color = P.color AND S.color = B.color;

I’ve looked long and hard and the best I found was this 2 table sqlite full join implemented with left joins and union alls:

SELECT employee.*, department.* 
FROM employee LEFT JOIN department 
ON employee.DepartmentID = department.DepartmentID 
UNION ALL SELECT employee.*, department.* 
FROM   department LEFT JOIN employee 
ON employee.DepartmentID = department.DepartmentID 
WHERE  employee.DepartmentID IS NULL;

I’m trying to modify this to work for more than 2 tables but I’m new to SQL and I’m not getting too far. Is it possible to get this result in a reasonable amount of time?

I think I have a correct implementation for 3 tables (it might not be correct) but I still can’t seem to get it for 4. Here’s what I have for 3:

SELECT S.pair, C.ball, P.bluejeans 
FROM Socks S LEFT JOIN Caps C LEFT JOIN Pants P 
ON C.color = S.color AND P.color = S.color 
UNION ALL 
SELECT S.pair, C.ball, P.bluejeans 
FROM Socks S LEFT JOIN Caps C LEFT JOIN Pants P 
ON S.color = C.color AND S.color = P.color 
WHERE S.color IS NULL;

Any help is much appreciated

  • 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-12T12:11:16+00:00Added an answer on June 12, 2026 at 12:11 pm

    The general construction for a full outer join between two tables A and B in SQLite indeed is:

    SELECT ... FROM A LEFT JOIN B ON ...
    UNION ALL
    SELECT ... FROM B LEFT JOIN A ON ... WHERE A.key IS NULL
    

    Now create a view SocksCaps for the full outer join between Socks and Caps:

    CREATE VIEW SocksCaps AS
    SELECT ... FROM Socks LEFT JOIN Caps ON ...
    UNION ALL
    SELECT ... FROM Caps LEFT JOIN Socks ON ... WHERE Socks.color IS NULL
    

    Do the same for Pants and Boxers.

    Then treat these views just like tables and do a full outer join with the same construction:

    SELECT ... FROM SocksCaps LEFT JOIN PantsBoxers ON ...
    UNION ALL
    SELECT ... FROM PantsBoxers LEFT JOIN SocksCaps ON ... WHERE SocksCaps.color IS NULL
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to join two tables based on columns with different types. The first
I need to write a select query that joins the tables based on a
I need to join two tables from different MySQL (PHP) connection strings and different
I need help regarding JOIN tables to get category name & author name from
I have 3 tables I need to join. The contracts table is the main
I have two tables and need to retrieve some columns from both tables based
I am making a cookie based favorite system and need to join data from
I have two tables which I need to join. First Table: EFF_DATE RATE CURRENCY
I need to delete from two tables, based on a query in one table
I have three tables I need to join. The first two are easy and

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.