?
Solved

query for non-matching records between 2 tables - ms sql

Posted on 2005-05-11
5
Medium Priority
?
204 Views
Last Modified: 2010-04-20
Just need a query to find missing records in the second table.
0
Comment
Question by:anidhir
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
rafrancisco earned 500 total points
ID: 13980693
SELECT *
FROM YourTable1 A
WHERE NOT EXISTS (SELECT 'X' FROM YourTable2 B
                               WHERE A.ID = B.ID)
0
 
LVL 21

Expert Comment

by:Kevin3NF
ID: 13980708
Select A.*
From Table1 A
RIGHT join Table2 B
on A.id = B.ID
Where A.ID is null
0
 
LVL 21

Expert Comment

by:Kevin3NF
ID: 13980719
Select B.*
From Table1 A
RIGHT join Table2 B
on A.id = B.ID
Where A.ID is null

My bad....ignore the first one.  
0
 

Author Comment

by:anidhir
ID: 13980777
Thanks !
0
 
LVL 21

Expert Comment

by:Kevin3NF
ID: 13980837
Just an FYI....and I'm not sure on this, but I believe the NOT Exists will take longer than the right join I presented.  I may be thinking of NOT IN though (posted for future readers of this thread :-)     )
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
This shares a stored procedure to retrieve permissions for a given user on the current database or across all databases on a server.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Suggested Courses

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question