table1 eno ename --- ----- 1 Wendy 2 Heidy 3 Scott 4 Tiger table2 eno1 eno2 ---- ---- 1 2 3 4 table1とtable2を、 結合して、以下の出力をする 出力結果 eno1 ename1 eno2 ename2 ---- ------ ---- ------ 1 Wendy 2 Heidy 3 Scott 4 Tiger
with table1 as( select 1 as eno,'Wendy' as ename from dual union select 2,'Heidy' from dual union select 3,'Scott' from dual union select 4,'Tiger' from dual), table2 as( select 1 as eno1,2 as eno2 from dual union select 3,4 from dual) select b.eno1,max(decode(a.eno,b.eno1,a.ename)) as ename1, b.eno2,max(decode(a.eno,b.eno2,a.ename)) as ename2 from table1 a,table2 b where a.eno in(b.eno1,b.eno2) group by b.eno1,b.eno2 order by b.eno1,b.eno2;
結合条件で、in述語を使ってます