Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2010
    Posts
    2

    Unanswered: Finding difference between two tables

    I have a table, say table A. This table, I created after importing values that are in tableA.csv. After some time, tableA.csv got updated and there are few records that are added, updated and deleted from the earlier version. I wish to sync my table A based on the updated tableA.csv. Pl. note that there is no timestamp in tableA.CSV and this CSV contains all the records and is not a 'delta' and I don't have any control over that.

    More clearly,

    Table 1

    Roll No (Pkey) Name marks

    101 JK 121
    102 AJ 141
    103 BR 151
    104 SH 127
    105 AB 128
    106 AM 221

    Table 2
    Roll No (Pkey) Name marks

    101 JK 121
    102 AJ 141
    103 BRS 151
    104 SH 127
    105 AB 125
    106 AM 221
    107 AD 220
    108 AX 229


    RESULT OF SQL SHOULD BE:

    103 BRS 151
    105 AB 125


    How do I get this delta, which would have the above result, which shows the records that were updated!!

    Thanks

  2. #2
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    Something like
    Code:
    (
     select * from A 
     except
     select * from B
    ) -- Rows in A that are not in B
    union all
    ( 
     select * from B 
     except
     select * from A
    ) -- rows in B that are not in A

  3. #3
    Join Date
    Aug 2010
    Posts
    2
    Hi Shammat,

    Thanks for the reply. I think the above query would give me the records that are present only in one and not in both! Basically, I want only those records that are present in Table B, which does not have a matching records in table A. i.e those records which are updated, deleted or inserted in table B. Also, pl. note that table B is a superset of table A, with the possibility of few updates to the records, few deleted records and few insertion.

    I hope I am clear.

    Anyway thanks for the reply.

  4. #4
    Join Date
    Nov 2003
    Posts
    2,933
    Provided Answers: 12
    The just leave out the second part of the UNION ALL

Posting Permissions

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