Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Help with simple query

Posted on 2014-12-03
1
Medium Priority
?
86 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 66

Accepted Solution

by:
Jim Horn earned 2000 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

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…
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.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Screencast - Getting to Know the Pipeline

824 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