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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1596
  • Last Modified:

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

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
BostonMA
Asked:
BostonMA
  • 2
  • 2
2 Solutions
 
BostonMAAuthor Commented:
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
 
BrandonGalderisiCommented:
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
 
BrandonGalderisiCommented:
no... you need a left outer join.  The "outer" is optional and implied when you use left, right or full.
0
 
BostonMAAuthor Commented:
Thanks guys.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now