Compare data for 4 columns

  • Hi,

    Can anybody please help with a SQL query to compare 4 column values between 2 tables to check if any data changes have taken place for a unique row ID ?

    Many thanks.

     

     

    • This topic was modified 4 years, 9 months ago by  pwalter83.
  • You've been around long enough to know that you should provide sample data and expected results.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • Here's a guess at what you want:

    (
    SELECT 'Table1' TableName,ID,Col1,Col2,Col3,Col4
    FROM Table1 t1
    WHERE EXISTS(SELECT * FROM Table2 t2 WHERE t2.ID = t1.ID)
    EXCEPT
    SELECT 'Table1' TableName,ID,Col1,Col2,Col3,Col4
    FROM Table2
    )
    UNION ALL
    (
    SELECT 'Table2' TableName,ID,Col1,Col2,Col3,Col4
    FROM Table2 t2
    WHERE EXISTS(SELECT * FROM Table1 t1 WHERE t1.ID = t2.ID)
    EXCEPT
    SELECT 'Table2' TableName,ID,Col1,Col2,Col3,Col4
    FROM Table1
    )

     

     

     

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

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