Solved

Help with simple query

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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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