January 25, 2011 at 12:39 pm
Hi,
I wanted to find a way to check that the first table and the second table do not have any overlapping rows.
Will a union see the duplicate if there is one and not dup it in the result, or will it just one reslult set on top of the other?
select MemberID, HIC, ICD9 from ##DM_TblExcel60Joined2 UNION select MemberID, HIC, ICD9 from ##DM_SummaryReviewJoined2
Thanks in advance
January 25, 2011 at 12:45 pm
Union concatenates the two resultsets then eliminates duplicates. Union All just concatenates the two resultsets.
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
January 25, 2011 at 12:46 pm
A quick test will show you how this works. Run this code in your analyzer:
;WITH cte (cola, colb, colc) AS
( SELECT 1,2,3),
cte2 (cola, colb, colc) AS
(SELECT 1,2,3)
SELECT
cola,colb,colc
FROM
cte
UNION ALL
SELECT
cola,colb,colc
FROM
cte2
;WITH cte (cola, colb, colc) AS
( SELECT 1,2,3),
cte2 (cola, colb, colc) AS
(SELECT 1,2,3)
SELECT
cola,colb,colc
FROM
cte
UNION
SELECT
cola,colb,colc
FROM
cte2
Never stop learning, even if it hurts. Ego bruises are practically mandatory as you learn unless you've never risked enough to make a mistake.
For better assistance in answering your questions[/url] | Forum Netiquette
For index/tuning help, follow these directions.[/url] |Tally Tables[/url]
Twitter: @AnyWayDBA
January 25, 2011 at 3:14 pm
Thank you both. Ran the code and makes perfect sense!!
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply