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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:47:40+00:00 2026-05-27T11:47:40+00:00

i have two temporary table Table 1 ID1 Name ID2 Single —————————————————- 1 ABC

  • 0

i have two temporary table
Table 1

 ID1         Name        ID2           Single
----------------------------------------------------
 1            ABC         1            100
 2            DEF         1            200

Table 2

 ID1         Name        ID2           Monthly
----------------------------------------------------
 3            PQR         2            500
 4            LMN         2            600
 1            ABC         2            700
 2            DEF         2            800

I want Output

 ID1         Name        ID2            Single   Monthly
--------------------------------------------------------
 1            ABC         1            100        700
 2            DEF         1            200        800
 3            PQR         2            NULL       500
 4            LMN         2            NULL       600

I used all Joins , Union ALL , Union nothing working
thanks in advance

  • 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-27T11:47:41+00:00Added an answer on May 27, 2026 at 11:47 am

    Hope you are using Sql Server 2008(other wise the insert statement in my query won’t work). Try this one.
    From the required out put, i guess you need all the values from table2 and there corresponding Single(Column name in table 1) value.

    DECLARE @tempTable1 TABLE (ID1 INT,Name VARCHAR(10),ID2 INT,Single INT)
    DECLARE @tempTable2 TABLE (ID1 INT,Name VARCHAR(10),ID2 INT,Monthly INT)
    
        INSERT INTO @tempTable1 VALUES
        (1            ,'ABC'         ,1            ,100),
        (2            ,'DEF'         ,1            ,200)
    
    INSERT INTO @tempTable2 VALUES
    (3            ,'PQR'         ,2            ,500  ),
    (4            ,'LMN'         ,2            ,600  ),
    (1            ,'ABC'         ,2            ,700  ),
    (2            ,'DEF'         ,2            ,800 );
    SELECT
                    T2.ID1
                    ,T2.Name
                    ,T2.ID2
                    ,T1.Single
                    ,T2.Monthly
    
    FROM            @tempTable2 T2
    LEFT OUTER JOIN @tempTable1 T1
    ON              T2.ID1 = T1.ID1
    ORDER BY        T2.ID1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have two temporary table Table 1 ID1 Name ID2 Single ---------------------------------------------------- 1 ABC
I have two identical tables and need to copy rows from table to another.
I have two tables from two different databases. For example: Table: Articles1 - Database:
I have a statement that SELECTs distinct rows from a table with a two
I have two tables, Hello and World: Hello has two columns id(int) and id1(int,
I have a temporary table I'm creating in a sproc that houses my user
I have created a sql function in SQLServer 2008 that declared a temporary table
I have written below stored procedure. In which i need to create Two Temporary
I have two mysql tables: /* Table users */ CREATE TABLE IF NOT EXISTS
I have two tables, users and followers : Table users : id INT, PRIMARY_KEY

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.