Connecting Tech Pros Worldwide Forums | Help | Site Map

Problems with select statement

Newbie
 
Join Date: Feb 2008
Posts: 4
#1: Mar 5 '08
I have 2 tables:

Customer Table
-CustomerID
-CustomerName
-CustomerState

Invoice Table
-InvoiceID
-CustomerID

I am having problems writing a select statement to find out which states have no customers in the invoice table...

Any ideas?

I have tried this:

select customerState
from customers
where customerID not in
(select customerID
from invoices)

ck9663's Avatar
Expert
 
Join Date: Jun 2007
Posts: 1,925
#2: Mar 5 '08

re: Problems with select statement


Quote:

Originally Posted by ProgrammingStudent

I have 2 tables:

Customer Table
-CustomerID
-CustomerName
-CustomerState

Invoice Table
-InvoiceID
-CustomerID

I am having problems writing a select statement to find out which states have no customers in the invoice table...

Any ideas?

I have tried this:

select customerState
from customers
where customerID not in
(select customerID
from invoices)


It's usually a problem when you have NULLs somewhere. Try:
Expand|Select|Wrap|Line Numbers
  1. select customerState 
  2. from customers
  3. where customers.customerID not in (select isnull(invoices.customerID,'') from invoices)
Tell us what happen.

-- CK
Reply