Reputation: 25
Construct a SQL query that will list the Street,City,State,ZipCode of all the addresses that DO NOT have a customer associated with them.
I am having issues understanding what this question is asking me to do. I can get as far as selecting Street, City, State, and ZipCode.
I am using SQL Server 2012
I have two tables: Customers (CustomerID (PK), CustomerName, CustomerAddressID(FK)) Address(AddressID (PK),Street,City,State,ZipCode)
Upvotes: 0
Views: 68
Reputation: 4476
It's asking you to find all Addresses that don't have an associated Customer (so they may have an AddressId but no associated CustomerAddressId. To get that you could use the following:
SELECT a.*
FROM Address a
LEFT JOIN Customer c
on c.CustomerAddressId = a.AddressId
WHERE c.CustomerId IS NULL
Upvotes: 1