Solved

Displaying unique records in SQL

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
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.

707 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