Solved

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

Posted on 2008-10-15
4
1,587 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
  • 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 500 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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

810 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