Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Displaying unique records in SQL

Posted on 2012-04-09
1
Medium Priority
?
312 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 70

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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
It is possible to export the data of a SQL Table in SSMS and generate INSERT statements. It's neatly tucked away in the generate scripts option of a database.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

610 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