基本的な1対1の外部結合を理解されておられるようですので、1対nの外部結合は外部テーブル(今回のテーブルAに該当)に複数のleft join
できることを応用すれば解決できるはずです。
第三者への有益な情報を目指して簡単なところから記載します。
記載されているSQLは質問と若干違います。MySQLのテーブル構成および実行結果はSQL Fiddleのリンク先を参照してください。
なお質問にある変換前のOracleのSQLは多重外部結合なのでOracle 11g
以前では下記のエラーが発生して動きません。
ORA-01417: 表が少なくとも1つの他の表に外部結合されている可能性があります。
SQL Fiddleは11gが対象で例示できないため、冗長ですがwith句でテーブルを代用しています。
もちろん実行は12c以降で行ってください。
A left outer join on B
まずはテーブルAとBを結合します。(既に質問で例示されているSQLと類似しています)
-- 2 tables in Oracle
with A as
(select 1 id, 'name1' name from dual union all
select 2 id, 'name2' name from dual union all
select 3 id, 'name3' name from dual union all
select 4 id, 'name4' name from dual union all
select 5 id, 'name5' name from dual)
,B as
(select 1 id, 'customer1' customer_name, 'address1' address from dual union all
select 2 id, 'customer2' customer_name, 'address2' address from dual union all
select 4 id, 'customer4' customer_name, 'address4' address from dual)
select A.id, name,
B.address
from A, B
where A.id = B.id(+)
order by A.id
-- 2 tables in SQL Server
select A.id, name,
B.address
from A
left join B on A.id = B.id
order by A.id
A on B, C
次に複数テーブルの外部結合です。
テーブルAとBに加えてテーブルAとCも外部結合します。
left join
を複数行積むことで、1つの外部テーブルに複数のテーブルを連結できます。
まだテーブルBとCは結合していません。
-- A on B, C in Oracle
with A as
(select 1 id, 'name1' name from dual union all
select 2 id, 'name2' name from dual union all
select 3 id, 'name3' name from dual union all
select 4 id, 'name4' name from dual union all
select 5 id, 'name5' name from dual)
,B as
(select 1 id, 'customer1' customer_name, 'address1' address from dual union all
select 2 id, 'customer2' customer_name, 'address2' address from dual union all
select 4 id, 'customer4' customer_name, 'address4' address from dual)
,C as
(select 1 id, 'address1' address, 'tel1' tel from dual union all
select 3 id, 'address3' address, 'tel3' tel from dual union all
select 5 id, 'address5' address, 'tel5' tel from dual)select A.id, name,
B.address,
C.tel
from A, B, C
where A.id = B.id(+)
and A.id = C.id(+)
order by A.id
-- A on B, C in SQL Server
select A.id, name,
B.address,
C.tel
from A
left join B on A.id = B.id
left join C on A.id = C.id
order by A.id
A on B, C and B on C
そろそろ厄介なところで、Oracleでも12cでようやく(+)が対応したSQLです。
とは言えANSI準拠の外部結合ならば、AとCの結合条件にandを加えてBとCを結合するだけです。
-- A on B, C and B on C in Oracle 12c-
with A as
(select 1 id, 'name1' name from dual union all
select 2 id, 'name2' name from dual union all
select 3 id, 'name3' name from dual union all
select 4 id, 'name4' name from dual union all
select 5 id, 'name5' name from dual)
,B as
(select 1 id, 'customer1' customer_name, 'address1' address from dual union all
select 2 id, 'customer2' customer_name, 'address2' address from dual union all
select 4 id, 'customer4' customer_name, 'address4' address from dual)
,C as
(select 1 id, 'address1' address, 'tel1' tel from dual union all
select 3 id, 'address3' address, 'tel3' tel from dual union all
select 5 id, 'address5' address, 'tel5' tel from dual)
select A.id, name,
B.address,
C.tel
from A, B, C
where A.id = B.id(+)
and A.id = C.id(+)
and B.address = C.address(+)
order by A.id
-- A on B, C and B on C in SQL Server
select A.id, name,
B.address,
C.tel
from A
left join B on A.id = B.id
left join C on A.id = C.id
and B.address = C.address
order by A.id
A, D and A on B on C and A on C and D on B
最後にこれまでの内容を踏まえてテーブルDを結合します。
AとDをwhere句で結合するとBとDのleft joinでエラーになるので、inner joinでAとDを先に等価結合しておきます。
質問のSQLとは異なりますが、B on DでBを外部結合すると、Bにないレコードが消えて外部結合の意味が薄れるので、D on BでDを外部結合しています。
また外部結合であることを示すため、Dのcustomer_nameとsexにnullが入っているレコードがあります。
-- A, D and A on B on C and A on C and D on B in Oracle 12c-
with A as
(select 1 id, 'name1' name from dual union all
select 2 id, 'name2' name from dual union all
select 3 id, 'name3' name from dual union all
select 4 id, 'name4' name from dual union all
select 5 id, 'name5' name from dual)
,B as
(select 1 id, 'customer1' customer_name, 'address1' address from dual union all
select 3 id, 'customer3' customer_name, 'address3' address from dual union all
select 4 id, 'customer4' customer_name, 'address4' address from dual)
,C as
(select 1 id, 'address1' address, 'tel1' tel from dual union all
select 3 id, 'address3' address, 'tel3' tel from dual union all
select 5 id, 'address5' address, 'tel5' tel from dual)
,D as
(select 1 id, 'customer1' customer_name, '1' sex from dual union all
select 2 id, 'customer2' customer_name, '2' sex from dual union all
select 3 id, 'customer3' customer_name, '3' sex from dual union all
select 4 id, 'customer4' customer_name, '4' sex from dual union all
select 5 id, 'customer5' customer_name, '5' sex from dual)
select A.id, name,
B.address,
C.tel,
D.sex
from A, B, C, D
where A.id = D.id
and A.id = B.id(+)
and A.id = C.id(+)
and B.address = C.address(+)
and B.customer_name = D.customer_name(+)
order by A.id
-- A, D and A on B on C and A on C and D on B in SQL Server
select A.id, name,
B.address,
C.tel,
D.sex
from A
inner join D on A.id = D.id
left join B on A.id = B.id
and D.customer_name = B.customer_name -- D on B
left join C on A.id = C.id
and B.address = C.address
order by A.id
(+)
はLEFT OUTER JOIN
に変換できることは質問文に既に記載の通りだと思いますが…。