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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:24:23+00:00 2026-05-28T21:24:23+00:00

table1 | id | value ——————– 1 | john 2 | frank 3 |

  • 0
table1 | id | value
--------------------
          1 | john
          2 | frank
          3 | patel
          4 | jim

table2 | id | value
--------------------
          6 | steve
          7 | tim
          8 | sunny
          9 | bhaskar

merged | tabid1 | tabid2
------------------------------
         3      | 7
         4      | 8

output needed:

    output  | tabid1 | tabval1 | tabid2 | tabval2
              1      | john    | NULL   | NULL
              2      | frank   | NULL   | NULL
              3      | patel   | 7      | tim
              4      | jim     | 8      | sunny
              NULL   | NULL    | 6      | steve
              NULL   | NULL    | 9      | bhaskar

I tried:

SELECT * 
FROM table1
LEFT JOIN merged m1 ON table1.id = m1.tabid1, merged m2
RIGHT JOIN table2 ON table2.id = m2.tabid2

But its giving 16 rows instead of required 6

  • 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-28T21:24:23+00:00Added an answer on May 28, 2026 at 9:24 pm
    select table1.id,table1.value,table2.id,table2.value 
         from table1 left join merged on table1.id=merged.tabid1 
                left join table2 on merged.tabid2=table2.id 
    union 
    select table1.id,table1.value,table2.id,table2.value 
         from table2 left join merged on table2.id=merged.tabid2
         left join table1 on merged.tabid1=table1.id ;
    

    or with right join:

    SELECT * FROM 
        table1 LEFT JOIN merged on table1.id=merged.tabid1 
               LEFT JOIN table2 ON merged.tabid2=table2.id  
    UNION 
    SELECT * FROM 
        table1 RIGHT JOIN merged on table1.id=merged.tabid1 
               RIGHT JOIN table2 ON merged.tabid2=table2.id WHERE table1.id IS NULL;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to insert column1 from table1 to column1 in table2. If the value
If I have two tables with following columns: Table1: [id,value] Table2: [id,comment] where id
Using Access 2003 Table1 ID Name Value 001 Raja 100 002 Ramu 200 004
Scenario: I have a table1(col1 char(5)); A value in table1 may '001' or '01'
table1 -> id, time_stamp, value This table consists of 10 id's. Each id would
Table1 has u_name, Table2 has u_name, u_type and u_admin Table1.u_name is unique. But neither
Cannot insert the value null into column 'COLUMN1',table'DB1.dbo.table1';Column does not allow nulls. Insert fails.the
I have 2 tables Table1 with columns [BId,Name,Amount] Table2 with columns [CId,BId, ExpenseType,Expense]. BId
Table1 ... LogEntryID *PrimaryKey* Value ThresholdID - - - Link to the appropriate threshold
UPDATE table1, tmpList SET table1.ts = tmpList.ts_value WHERE table1.id = tmpList.id UPDATE table2, tmpList

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.