|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Sunday, July 05, 2009 6:39 AM
Points: 39,
Visits: 18
|
|
|
|
|
|
Forum 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
|
|
|
|
|
SSC 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)
|
|
|
|
|
Forum 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
|
|
|
|