Compare Data In 2 Similar Tables – SQL Server

Posted: January 25, 2013 in MySQL, SQLServer
Tags: ,

— Below query gives all difference records between old & new tables one below other
(SELECT * FROM Table_Old
UNION
SELECT * FROM Table_New)
EXCEPT
(SELECT * FROM Table_Old
INTERSECT
SELECT * FROM Table_New)

— Below query gives all difference records from old table first and then all difference records from new table
select * from
(
select * from Table_Old
except
select * from Table_New
) as T
union all
select * from
(
select * from Table_New
except
select * from Table_Old
) as T

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s