Solved

Help with simple query

Posted on 2014-12-03
1
75 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
[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 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

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.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…

740 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