Reputation: 1
I have a database with two tables Locations and Accounts. Both tables have a field named LocationID and a relationship exists between the two. How can I get a list of all Locations that don't have an account? Ultimately every Location should have an account, but we are trying to track down which ones don't at the moment.
Upvotes: 0
Views: 56
Reputation: 4647
SELECT LocationID from Location Left outer Join accounts on Location.LocationID = Accounts.LocationID where accountsID is null.
Syntax will need to be cleaned up but you need an outer join that will give you all the locations and then filter on the records that have a null value in the field from the Accounts table.
Upvotes: 1