Solved

Displaying unique records in SQL

Posted on 2012-04-09
1
300 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

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…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
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.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

706 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

12 Experts available now in Live!

Get 1:1 Help Now