Home Forums Programming General problem in merging 2 sql queries into a single query to distinguish old and new.plz help!! RE: problem in merging 2 sql queries into a single query to distinguish old and new.plz help!!

  • suvo.kundu (1/12/2013)


    in my table i have the records like

    Id Record1 Record2 Level gid

    1testRec1 testRec2 0 1

    2testRec11 testRec22 0 2

    3testRec111 testRec222 0 3

    4testRec111 testRec2222 0 4

    5newtestRec newtestRec2 1 1

    I want to show records like

    Id OldRecord1 NewRecord1 OldRecord2 NewRecord2

    1 testRec1 newtestRec1 testRec2 newtestRec2

    2 testRec11 NoNewRecord testRec22 NoNewRecord

    3 testRec22 NoNewRecord testRec33 NoNewRecord

    4 testRec33 NoNewRecord testRec33 NoNewRecord

    actually i have 2 querys

    this is for old record

    select * from tablename where level=0

    this is for New record

    select * from tablename where level=1

    I want to merge this into a single record set as old and new..plz help

    SELECT *

    FROM tablename old

    INNER JOIN tablename new

    ON old.id = new.id

    WHERE old.LEVEL = 0

    AND new.LEVEL = 1;

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events