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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:45:52+00:00 2026-06-05T11:45:52+00:00

Tables structure are below : Table1 (ID int, value1 int,…) ID Value1 —- ——–

  • 0

Tables structure are below :

Table1 (ID int, value1 int,...)

ID       Value1
----    --------
1        10
2        20
5        12


Table2 (ID int, value2 int,...)

ID       Value2
----    --------
1        13
3        24
4        11


Table3 (ID int, value3 int,...)
ID       Value3
----    --------
4        150
5        100

My expected output is below.

ID       Value1        Value2        Value3
----    --------      --------      --------
1         10            13             NULL
2         20            NULL           NULL
3         NULL          24             NULL
4         NULL          11             150
5         12            NULL           100

It should be noted that above tables is huge and I want to have best performance.

My query suggestion is below :

Select ID, 
       SUM(Value1) AS Value1, 
       SUM(Value2) AS Value2,
       SUM(Value3) AS Value3 
From (
    Select ID, Value1 , NULL as value2, NULL as value 3
    From Table1

    Union ALL

    Select ID, NULL , value2, NULL
    From Table2

    Union ALL

    Select ID, NULL, NULL, value 3
    From Table3
    )Z
Group By Z.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-06-05T11:45:54+00:00Added an answer on June 5, 2026 at 11:45 am

    Assuming you only have one value per id, this should do the trick:

    SELECT aux.ID, t1.Value1, t2.Value2, t3.Value3
    FROM 
    (SELECT ID FROM Table1
     UNION
     select ID FROM Table2
     UNION
     SELECT ID FROM Table3) aux
    LEFT OUTER JOIN Table1 t1 ON aux.ID = t1.ID
    LEFT OUTER JOIN Table2 t2 ON aux.ID = t2.ID
    LEFT OUTER JOIN Table3 t3 ON aux.ID = t3.ID
    

    If you’ve more than one value:

    SELECT aux.ID, SUM(t1.Value1) as 'Value1', SUM(t2.Value2) as 'Value2', SUM(t3.Value3) as 'Value3'
    FROM 
    (SELECT ID FROM Table1
     UNION
     select ID FROM Table2
     UNION
     SELECT ID FROM Table3) aux
    LEFT OUTER JOIN Table1 t1 ON aux.ID = t1.ID
    LEFT OUTER JOIN Table2 t2 ON aux.ID = t2.ID
    LEFT OUTER JOIN Table3 t3 ON aux.ID = t3.ID
    GROUP BY aux.ID
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My table structure is below: CREATE TABLE [ACC].[Document]( [DocumentID] [int] IDENTITY(1,1) NOT NULL, [Date]
My table structure is below : MyTable (ID Int, AccID1 Int, AccID2 Int, AccID3
I have mysql database structure like below: CREATE TABLE test ( id int(11) NOT
Based on the following data structure. CREATE TABLE [Parent] ( Id INT, Name nvarchar(100)
newb question there. Having MySQL database/tables structure below: CREATE DATABASE `dbTest` CREATE TABLE IF
Similar to these other questions noted below, I have two tables with the structure:
I have a mysql database with a table structure like below : Table Name
I have a table with below structure. I am not having control over changing
I have a table structure having a EMP_DATE column as below ID EMP_DATE ----
I have two table masterTbl and detailTbl which structure is given below... --PRIMARY TABLE

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.