SQL puzzle

  • create TABLE xyz

    (

    id_xyz int

    )

    DROP TABLE pqr

    CREATE TABLE pqr

    (

    id_pqr int

    )

    INSERT INTO xyz VALUES (101)

    INSERT INTO pqr VALUES (101)

    INSERT INTO xyz VALUES (102)

    INSERT INTO pqr VALUES (102)

    INSERT INTO xyz VALUES (103)

    INSERT INTO pqr VALUES (103)

    INSERT INTO xyz VALUES (104)

    INSERT INTO pqr VALUES (105)

    -- Ur answer !!

    SELECT id_xyz

    FROM xyz

    where id_xyz not in (select Id_pqr from pqr)

    union all

    SELECT id_pqr

    FROM pqr

    where id_pqr not in (select id_xyz from xyz)

    enjoy!

     

  • Perhaps it's the difference in language and culture, Sandeep.  You post didn't sound right at all.  There is a way to ask for help especially on these types of forums... your post seemed like so many others where the requester thought it would inspire others to do their homework by issuing a "challenge".  That and the fact that you requested to compare two employee tables (should never happen in a real data base) make us all think that this is homework.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • I thought the puzzle was BS also and I still do.  Hence, my NZDF answer.

     

  • select ID from Emp1 where ID not in (select ID from Emp2)     UNION         select ID from Emp2 where ID not in (select ID from Emp1)

     

  • All of the banter here has shown the multiple methods of solving a SQL problem. I for one have learned no matter what the initial impetus of the post.

    RegardsRudy KomacsarSenior Database Administrator"Ave Caesar! - Morituri te salutamus."

Viewing 5 posts - 16 through 19 (of 19 total)

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