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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T02:39:59+00:00 2026-05-24T02:39:59+00:00

I have multiple tables where there are roughly 10 common columns, but some tables

  • 0

I have multiple tables where there are roughly 10 common columns, but some tables have 1-2 extra columns.

I would like to combine all these tables into one table with a row for each row from each table, with NULL values for any columns that didn’t exist in each particular row’s source table.

So my inputs look roughly like this:

table1
id  |  colA  | colB

table2
id  |  colA  | colB  | colC

table3
id  |  colA  | colB  | colD

And I am trying to get this:

allTables
id  |  colA  | colB  | colC | colD

In the above example all rows from table1 would have NULL values for colC and colD in allTables, all rows from table2 would have null values for colD, and all rows from table3 would have null values in colC.

A couple notes:

  • The column id is not the same or related between tables in any way
  • My example shows 3 tables, but I have about 8-9.
  • Duplicate rows exist within each source table and should be preserved.

In particular I’m interested if there’s an answer similar to the top voted one here or something like it that’s more generalized.

  • 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-24T02:39:59+00:00Added an answer on May 24, 2026 at 2:39 am
    SELECT
        id,
        colA,
        colB,
        NULL AS colC,
        NULL AS colD
    FROM
        Table1
    UNION ALL
    SELECT
        id,
        colA,
        colB,
        colC,
        NULL AS colD
    FROM
        Table2
    UNION ALL
    SELECT
        id,
        colA,
        colB,
        NULL AS colC,
        colD
    FROM
        Table3
    

    Since the ids are not related, you might also want to track which table the row came from in case there are duplicates between the tables. To do that, just have a hard-coded value with an alias with a different value in each of the three SELECT statements.

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

Sidebar

Related Questions

I would like to have multiple users that share the same tables in the
I have multiple html tables. Each table has the same number of columns but
I have multiple tables with an id component. I'd like to use LINQ to
If I have queries on multiple tables like: d = Relations.objects.filter(follow = request.user).filter(date_follow__lt =
I have built a database on multiple tables. One of these tables has a
I have some periodic data, but the amount of data is not a multiple
we have certain tables where we have multiple columns which together make the primary
We have multiple offices, and within each office there are multiple departments (some departments
I have multiple tables in my database. Let's say the table users looks like
I have multiple data tables per page, ranging from 4 to 8 ish. All

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.