Multiple FULL OUTER JOIN on multiple tables

前端 未结 5 1969
暗喜
暗喜 2020-12-23 20:36

I have multiple outer joins

SELECT  A.column2
        , B.column2
        , C.column2
FROM 
(
    (SELECT month, column2 FROM table1) A
    FULL OUTER JOIN
          


        
5条回答
  •  半阙折子戏
    2020-12-23 21:10

    One of the ways to do this could be create "anchor" table from all possible data from all three tables and then use left outer join:

    select
        A.column2,
        B.column2,
        C.column2
    from (
        select distinct month from table1
        union
        select distinct month from table2
        union
        select distinct month from table3
    ) as X
        left outer join table1 as A on A.month = X.month
        left outer join table2 as B on B.month = X.month
        left outer join table3 as C on C.month = X.month
    

提交回复
热议问题