By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,516 Members | 1,126 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,516 IT Pros & Developers. It's quick & easy.

Problems with select statement

P: 4
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)
Mar 5 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
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
Mar 5 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.