、あなたはこのようなものになってしまいます: - Postgresではでサポートされてではなく、SQL Serverの -
select *
from table1 a full outer join
table2 b
on b.product_id = a.product_id
... full outer join
tableN c
on c.product_id = coalesce(b.product_id, a.product_id)
using
句これを簡素化。列の名前はすべて同じであると仮定します。
代わりに、運転台があります。あなたは便利なすべての製品のテーブルを持っていない場合は、作成することができます
select *
from (select product_id from table1 union
select product_id from table2 union
. . .
select product_id from tableN
) driving left join
table1 a
on a.product_id = driving.product_id left join
table2 b
on b.product_id = driving.product_id
... full outer join
tableN c
on c.product_id = driving.product_id;
これは解釈が容易であるべきとon
句は、簡略化されています。
最後に、共通の列が必要な場合があります。もしそうなら、単にunion all
を使用します。
select product_id, col1, col2, col3 from table1 union all
select product_id, col1, col2, col3 from table2 union all
. . .
select product_id, col1, col2, col3 from tableN;
これはNULL
値を持つ列の増殖を防ぐことができます。
互換性のないデータベースタグを削除しました。実際に使用しているデータベースにタグを付けてください。 –
また、テーブルエイリアスcへの結合がc.product_idでフィルタリングされていませんb.product_idでフィルタリングされています – Hogan