Simplified I have two tables NAMES (with columns ID and NAME) and ADRESSES (with columns COUNTRY and CITY and NAME_ID).
Example for NAMES:
1 - Hans
2 - Mark
3 - Joseph
Example for ADRESSES:
Denmark - Kopenhagen - 1
Germany - Berlin - 3
I need to select all Names which either have no adress at all OR with their CITY but only when their country is... Denmark.
SELECT
NA.NAME AS NAME,
AD.CITY AS CITY
FROM NAMES AS NA
LEFT JOIN ADRESSES AS AD ON AD.NAME_ID = NA.ID
now when I add something like
WHERE AD.COUNTRY="Denmark"
or
WHERE (AD.COUNTRY="Denmark" OR AD.COUNTRY=NULL)
I still only get a list of Names with Cities in Denmark but not all other Names which have no Adress/City at all.
When I remove the condition of course I get all Names and existing Cities but even in all other countries.
The desired result would be:
Hans - Kopenhagen
Mark - NULL