Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Show content differences between two tables/views Expand / Collapse
Author
Message
Posted Thursday, May 15, 2008 6:36 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, July 05, 2009 6:39 AM
Points: 39, Visits: 18
Comments posted to this topic are about the item Show content differences between two tables/views
Post #501242
Posted Thursday, October 16, 2008 1:47 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, June 04, 2009 7:22 PM
Points: 1, Visits: 3
Hi Douwe,

I am quite new to SQL and I have a need to create a table (TableD)which would contain contents of TableA that do not exist in TableC and combining with contents of TableB that do not exist in TableC. All the tables have same number of columns and also identical column names. Combination of column1,column2 and column3 would give a unique key identifier. TableC contains over 1,000,000 records while TableA and TableB about 2,000,000 and 4,000,000 respectively.

Appreciate if you or other SQL gurus out there can assist me with creating a script to achieve this.

Kind regards,

Chris
Post #586776
Posted Thursday, October 16, 2008 2:42 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Sunday, July 05, 2009 6:39 AM
Points: 39, Visits: 18
You could try,

select *
into D
from A
where not exists (select 'x' from C where C.key=A.key)
union
select *
into D
from B
where not exists (select 'x' from C where C.key=B.key)
Post #586791
Posted Sunday, July 05, 2009 2:18 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 10, 2009 1:43 AM
Points: 1, Visits: 3
Using the Except operator, the following query returns any distinct values from TableA that are not also found in TableB.

SELECT * FROM TableA EXCEPT SELECT * FROM TableB

You may also use union all to find differences from the one and the other side .... as follows:

SELECT * FROM TableA EXCEPT SELECT * FROM TableB
unoin all
SELECT * FROM TableB EXCEPT SELECT * FROM TableA

Post #747314
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse