Solved

Help with simple query

Posted on 2014-12-03
1
69 Views
Last Modified: 2014-12-03
I have Customer table with Customer ID and Cust Name and other fields.

I have another Customer table Customer2

I need to find all the records in Customer2 that are not in Customer based on Customer ID and  Cust Name.
Ids may exist in both Names may be differant

I tried, but doesn't seem to work

SELECT * FROM CUSTOMER2 WHERE CUSTID NOT IN (SELECT CUSTID FROM CUSTOMER) AND
CUSTNAME NOT IN (SELECT CUSTNAME FROM CUSTOMER)
0
Comment
Question by:JElster
1 Comment
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 40479329
Give this a whirl..
SELECT c2.CustomerID, c2.CustomerName
FROM Customer2 c2
   -- LEFT JOIN means return all rows from c2..
   LEFT JOIN Customer c ON c2.CustomerID = c.CustomerID AND c2.CustomerName = c.CustomerName
--- then exclude the ones not found in Customer
WHERE c.CustomerID IS NULL

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
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.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now