Solved

Displaying unique records in SQL

Posted on 2012-04-09
1
301 Views
Last Modified: 2012-04-09
I have to tables (tblNamesAges, tblPeopleDetail) with the exact same columns (PersonName, PersonAge)

How do I write a query to display each record that does not have an exact match in both tables? (i.e. if a record exists in tblNamesAges but does not exist in tblPeopleDetail and vice versa, then display in the results.)
0
Comment
Question by:mwmiller78
1 Comment
 
LVL 69

Accepted Solution

by:
ScottPletcher earned 500 total points
ID: 37823875
Use a FULL OUTER JOIN, like this:


SELECT na.*, pd.*
FROM tblNameAges na
FULL OUTER JOIN tblPeopleDetail pd ON
    na.PersonName = pd.PersonName AND
    na.PersonAge = pd.PersonAge
WHERE
    na.PersonName IS NULL OR
    pd.PersonName IS NULL
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

920 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now