I have the following tables:
Table_1:
Value_ID Value_Code_1 Value_Code_2 Value_Code_3 1 465 325 129
Table_2:
ID Text 465 this is a value 325 this value is a different one 129 hello world
I need to replace the codes in Table_1 with the Text from Table_2. The way I thought about solving it seems quite long and hairy, is there a quicker, better way of doing this? I have to do this for around 40 columns and not 3 as in my example.
My code:
Select
first.ID,
first.string_value,
second.string_value,
third.string_value
from
(
Select
a.ID,
b.text as string_value
From
table_1 a
left join
table_2 b
on a.Value_Code_1 = b.ID
) first
left join on first.id = second.id
(
Select
a.ID,
b.text as string_value
From
table_1 a
left join
table_2 b
on a.Value_Code_2 = b.ID
) second
left join on first.id = third.id
(
Select
a.ID,
b.text as string_value
From
table_1 a
left join
table_2 b
on a.Value_Code_2 = b.ID
) third
Thank you.
You can do it simpler, like this:
You still need to do it for all 40 columns.