Data aggregation

  • I have 2 separate tables

    table1 looks like this

    ID salary

    -----------

    1 2000

    2 5000

    table 2 looks like this

    ID SalaryAbroad

    ------------------

    2 4000

    6 2000

    I need to write a query that produces the following result using the above 2 tables mentiones, ID is the column common to both the table

    ID Salary SalaryAbroad

    -----------------------------

    1 2000 0

    2 5000 4000

    6 0 2000

    Any help is greatly appreciated, as heere 2 tables are there and i need to merge them into 1 ?

    Thanks

  • Assuming table names are table1 and table2...

    select isnull(a.id,b.id),

    isnull(a.salary,0),

    isnull(b.salaryabroad,0)

    from dbo.table1 a

    full outer join

    dbo.table2 b

    on a.id = b.id

    order by isnull(a.id,b.id)

    _____________________________________
    Pablo (Paul) Berzukov

    Author of Understanding Database Administration available at Amazon and other bookstores.

    Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.
  • Thank you

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply