Results 1 to 2 of 2

Thread: inserting data

  1. #1
    Join Date
    Jul 2003

    Unanswered: inserting data

    I have 2 tables.

    Table A has existing records

    Table B has new records to be updated into Table A.

    However, I need to avoid duplication. What would be the best way to insert the data from table B into table A, but only if the data doesnt already exist in Table A. Is there a clause/function I can use?

    If riding in a plane is flying, then riding in a boat must be swimming. To experience the element, get out of the vehicle. Skydive!

  2. #2
    Join Date
    Apr 2002
    Toronto, Canada
    insert into tableA (PK, A2, A3)
    select PK, B2, B3
    from tableB
    where not exists
    (select 1 from tableA
    where PK = tableB.PK )

    it does not matter what you select in the subquery (i use 1, some use null, others use an asterisk), because the subquery returns true or false

    rudy | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts