COMPARE TWO TABLES COPY MATCHING VALUS TO TABLE_C

  • i have 3 table

    table_A

    table_B

    table_C

    TABLE_A

    SNO NAME ID

    1 RAJU 070491

    2 VAMSHI 089767

    3 ARUNA 068908

    TABLE_B

    SNO NAME ID

    2 RAJU 070491

    4 JKLKJ 098766

    I WANT COMPARE TWO TABLES(TABLE_A & TABLE_B) SELECT TABLE_A MATCHING VALUES COPY IN TABLE_C

    EX-

    SNO NAME ID

    1 RAJU 070491

  • You would need to do an "insert into" based on the results from an inner join.

    This might be a useful link http://technet.microsoft.com/en-us/library/ms188263(v=sql.105).aspx

    -------------------------------Posting Data Etiquette - Jeff Moden [/url]Smart way to ask a question
    There are naive questions, tedious questions, ill-phrased questions, questions put after inadequate self-criticism. But every question is a cry to understand (the world). There is no such thing as a dumb question. ― Carl Sagan
    I would never join a club that would allow me as a member - Groucho Marx

  • Try the INTERSECT command. The either insert into or put the results into the table.

    -- INSERT INTO TableC

    Select field1, field2

    -- INTO TableC

    from tableA

    INTERSECT

    Select field1, field2

    from tableB

    ;

    -------------------------------------------------------------
    we travel not to escape life but for life not to escape us
    Don't fear failure, fear regret.

  • --method1:

    insert into table_c

    select a.* from table_a a join table_b b

    on a.id = b.id

    -- method2

    insert into table_c

    select a.* from table_a a

    where exists (select 1 from table_b b where a.id = b.id)

    regards

    Siva Kumar

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

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