Add one table to another excluding duplicates

  • Hi,

    Can anyone give me a kick start on adding one table's data to another, without adding duplicates?

    Table T1 (e.g. ID, SocialSecurityNumber) (SocialSecurityNumber is unique)

    Table T2 (e.g. ID, SocialSecurityNumber)

    Add records from table T2 to T1, but do not add records from T2 that already exist in T1.

    Thanks in advance.

    Matt

  • I would probably try this way first. But other options exist.

    INSERT INTO t1(SocialSecurityNumber)

    SELECT SocialSecurityNumber

    FROM t2

    WHERE NOT EXISTS (SELECT 1

    FROM t1

    WHERE t1.SocialSecurityNumber = t2.SocialSecurityNumber

    )

  • Thank you very much!

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

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