FoxHoundPy
FoxHoundPy

Reputation: 25

SQL Server 2012 Query JOINS

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)

enter image description hereenter image description here

Upvotes: 0

Views: 68

Answers (1)

mal-wan
mal-wan

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

Related Questions