I have this table in mySQL intended to map some values to other values, for example countries to capitals.
I want to use it this way:
SELECT capital
FROM CountryData
WHERE country = 'France';
or rather, to update some other table:
UPDATE CustomerData
SET customerCapital =
SELECT capital
FROM CountryData
WHERE CountryData.country = CustomerData.customerCountry
The problem arises when the country is not found in the Country table. How can I have customerCapital set to some default value 'UNKNOWN' instead of NULL when customerCountry is not present in the CountryData table?
Check the
COALESCEfunction.However, I do not advise you to store an arbitrary value instead of NULL. Any other value than NULL is an information in itself. You want to show the lack of value, therefore you should use NULL.
It sounds like a cosmetic problem. If you want to show a value when you print the customerCapital to the screen, then you should, in the application code, transform the NULL into
UNKNOWN.