Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to subtract the results of one table from another in sql?

Posted on 2008-10-15
4
Medium Priority
?
1,594 Views
Last Modified: 2010-04-21
I have two tables:

Customers_New

Customers_Old

Each table has a customer id.  How do I show New customers who are not also old customers?  That is I want to take the Customers_New table and subtract out the Customers_Old. I tried a few different types of joins but none of them seemed to be doing anything that I expected.

I'm using SQl server 2000.
0
Comment
Question by:BostonMA
[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
  • 2
  • 2
4 Comments
 
LVL 4

Author Comment

by:BostonMA
ID: 22721885
I may have stumbled on it. Is this it:

select * from customers_new
inner join customers_old on customers_new.customerid = customer_old.customerid
0
 
LVL 39

Accepted Solution

by:
BrandonGalderisi earned 2000 total points
ID: 22721890
Assuming you have a common customer_id between the two.  Otherwise, change the ON and where line line to what is common

select cn.* from customers_new cn
left outer join customers_old co
on cn.customer_id = co.customer_id
where co.customer_id is null

0
 
LVL 39

Assisted Solution

by:BrandonGalderisi
BrandonGalderisi earned 2000 total points
ID: 22721899
no... you need a left outer join.  The "outer" is optional and implied when you use left, right or full.
0
 
LVL 4

Author Closing Comment

by:BostonMA
ID: 31506332
Thanks guys.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

715 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