Query Help - Find records with a 'missing' value from a table

wob

Board Regular
Joined
May 21, 2002
Messages
105
I'm sure this is an easy one for someone, but I can't figure it out!

I've got an address table, that includes customer_no and address_type fields.
Address_type can be several values, 'Home', 'Mail', 'Other', 'Business' and a few others.

The table is like this:

customer_no, address_type
1, Home
1, Mail
2, Home
2, Business
3, Other
4, Mail
4, Business

Note that customers can have more than one address set up.
How do I select customers that I have no 'Home' addresses for? (ie, customers 3 and 4)
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
It can be done using a Subquery. Basically, create a query that returns the Customer Numbers where the type is "HOME". Then, create a query that uses that as part of the criteria, returning records that are not found in that Subquery. Using DISTINCT will combine all the duplicate returns.

So, assuming your table name is "CustomerTable", that SQL code would look something like:
Code:
SELECT DISTINCT CustomerTable.customer_no
FROM CustomerTable
WHERE CustomerTable.customer_no Not In
(SELECT CustomerTable.customer_no
FROM CustomerTable
WHERE CustomerTable.address_type="Home");
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top