I have three fields in my table and I want to update them by joining three times to another table. I know that I have to use merge into
, but I couldn't find any similar query that uses merge into
and join
with only one table for multiple times.
The select
statement is something like this:
select * from TABLE t
inner join DESTINATION_TABLE d1
on t.CODE1 = d1.CODE
inner join DESTINATION_TABLE d2
on t.CODE2 = d2.CODE
inner join DESTINATION_TABLE d3
on t.CODE3 = d3.CODE
Now how can I update three fields (FIELD1
, FIELD2
, FIELD3
) from TABLE
by using fields from d1
, d2
, and d3
using merge into
?
EDIT:
The original query is:
select * from TOTAL
inner join GROUP_LEVEL_DETAIL gl1
on gl1.NAME = substr(GL, 1, instr(GL, ' -', 1))
inner join GROUP_LEVEL_DETAIL gl2
on GL2.NAME = replace(substr(GL, instr(GL, ' -', 1, 1), instr(GL, ' -', 1, 2) - instr(GL, ' -', 1, 1)), ' - ', '')
inner join GROUP_LEVEL_DETAIL gl3
on gl3.NAME = replace(substr(GL, instr(GL, '-', 1, 2), 500), '- ', '')
The sample data for TOTAL
is:
ID GL GL1_CODE GL2_CODE GL3_CODE
----- ----------------------------- ---------- ---------- -----------
1 Sample1 - Sample2 - Sample3 null null null
2 John - Jack - Harry null null null
The sample data for GROUP_LEVEL_DETAIL
is:
CODE NAME LEVEL_NO
--------- ----------- ------------
SMP1 Sample1 1
SMP2 Sample2 2
SMP3 Sample3 3
JCK1 Jack 1
JHN2 John 2
HRY3 Harry 3
And I want my TOTAL
table get like this after the update:
ID GL GL1_CODE GL2_CODE GL3_CODE
----- ----------------------------- ---------- ---------- -----------
1 Sample1 - Sample2 - Sample3 SMP1 SMP2 SMP3
2 John - Jack - Harry JCK1 JHN2 HRY3