First I am new to Postgres so I may be describing this problem incorrectly so please point me to an answer if it has already been answered.
I have a database with 10 columns. Lets say 4 columns all use the same codes for values (i.e the letter a, b, d, e) I want to rename all of these in the query to what they are matched with values in another table.
I have a very long approach at this stage involving a nested With statements. Is there a easy way to go from say:
table1
:
id | col1 | col2 | col3 | col4
------+------+------+------+------
Row_1 | a | c | d | e
Row_2 | c | c | c | c
Row_3 | e | d | d | c
Lookup Table:
code | value
-----+---------
a | apple
b | banana
c | catfish
d | dog
e | egg
Desired result:
Row_1 | apple | catfish | dog | egg
Row_2 | catfish | catfish | catfish | dog
Row_3 | egg | dog | dog | catfish