?
Solved

Displaying unique records in SQL

Posted on 2012-04-09
1
Medium Priority
?
310 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:Mike Miller
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 2000 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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

777 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