Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Show content differences between two tables/views


Show content differences between two tables/views

Author
Message
dj.miedema
dj.miedema
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
Points: 39 Visits: 18
Comments posted to this topic are about the item Show content differences between two tables/views
ckafang
ckafang
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
dj.miedema
dj.miedema
SSC Rookie
SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)SSC Rookie (39 reputation)

Group: General Forum Members
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)
m.gkountara
m.gkountara
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search