Click here to monitor SSC
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in
Home       Members    Calendar    Who's On

Add to briefcase

Comparing Two Different Tables, Showing Values In Table 1 Not in Table 2 Expand / Collapse
Posted Monday, April 15, 2013 7:23 PM
Valued Member

Valued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued MemberValued Member

Group: General Forum Members
Last Login: Thursday, January 28, 2016 8:35 PM
Points: 50, Visits: 158

I'd like to compare two tables, and show values found in table 1 which are NOT in table 2, then same for table 2, show values in table 2 which are NOT in table 1.

Here's what I came up with, looks ok?

select T1.[Name], T2.[Address]
from [dbo].[My Table 1] as T1
left join [dbo].[My Table 2] as T2 on T1.[Name]=T2.[Name]
where T2.[Address] is not null

Post #1442555
Posted Tuesday, April 16, 2013 1:18 AM



Group: General Forum Members
Last Login: Today @ 2:31 AM
Points: 7,894, Visits: 16,807
TableSource = CASE WHEN T1.[Name] IS NULL THEN 'Table2' ELSE 'Table1' END,
FROM [dbo].[My Table 1] T1
FULL OUTER JOIN [dbo].[My Table 2] T2
ON T1.[Name] = T2.[Name]
WHERE NOT T1.[Name] = T2.[Name]

“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw

For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
Exploring Recursive CTEs by Example Dwain Camps
Post #1442619
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse