I have a database where users must have a username and on another table have an optional contact_name that is given to them by each user.
For example:
user A might call user B 'FOO'
but user C calls user B 'BAR'
and user D might not have given user B a contact_name
so it should return NULL.
The query below works in getting me all the usernames and contact_names even when NULL which is the desired result.
SELECT Login.username, PhoneNumber.phone, AddressBook.contact_name FROM Login
LEFT OUTER JOIN PhoneNumber ON Login.id = PhoneNumber.user_id
LEFT OUTER JOIN AddressBook ON PhoneNumber.phone = AddressBook.phone
However, I only want to return WHERE AddressBook.user_id = 67 which will return the usernames and contact_names that User A is associated with.
Currently when I add WHERE AddressBook.user_id = 67 it doesn't return any of the contact_names with NULL values which is expected but I need those rows with NULL and without NULL contact_names.
How do I go about this?
Thanks