I have postgresql tables with values, for example:
Table region_data: region_name | population | region_code ------------+------------+------------- Region 1 | 120000 | A Region 2 | 200000 | A Region 3 | -1 | B Region 4 | -2 | -1
If some data may not be available (i.e. -1 and -2)
And tables containing translations for these values:
Table data_codes: code | meaning ------+----------------------- -1 | 'Data not available' -2 | 'Insufficient data' ...
and
Table region_types: type | meaning
I want to make a query (actually a view) that returns the human-readable translations provided by the data_code and region_types tables. For example, the view will return:
Region Name | Population | Region Type ------------+--------------------+------------- Region 1 | 120000 | Mountain Region 2 | 200000 | Mountain Region 3 | Data Not Available | Grassland Region 4 | Insufficient Data | Data Not Available
I tried to do some subqueries, but they return many duplicate rows where the code does not match any in the data_code table.
Please, help? Thanks!
Paulp source share