Wednesday, May 11, 2011

Find Data Difference Between Two Tables

If you are looking for a difference in data between of two tables? There are many whys to compare the data, here I am explaining two options. The ‘EXCEPT’ operator performs the compare between two tables: 

Option 1:
SELECT COL1, COL2, COL3 FROM table1

EXCEPT

SELECT COL1, COL2, COL3 FROM table2 

Option 2: 

Select * From Table_A where not exists (select 1 from Table_B where Table_A.Col1 = Table_B.Col1 and Table_A.Col2 = Table_B.Col2 and Table_A.Col3 = Table_B.Col3)
SQL to compare rows within two tables. difference between two tables. Show differences in DATA from two tables. sql query to return differences between two tables.  compare two tables in SQL Server 2012. compare two tables in SQL Server 2008. compare two tables in SQL Server 2005. calculate difference between two tables. Easily show rows that are different between two tables or queries. How to compare difference between two tables. Getting the difference between two sets of like data. compare differences between two tables. difference or changes between two rows from two tables 

1 comments:

Needs to work BOTH ways to get ALL differences:

(SELECT COL1, COL2, COL3 FROM table1

EXCEPT

SELECT COL1, COL2, COL3 FROM table2)

UNION

(SELECT COL1, COL2, COL3 FROM table2

EXCEPT

SELECT COL1, COL2, COL3 FROM table1)

Post a Comment