Home>

Here's how to apply two query statements with the same structure if I want to outer join query A to query B.
It would be helpful if you could point it out with a specific code.

Query A

select
 wd.id,
 ...
 ...
 from
 sss.dd
 inner join ddd.lll on aa.id = ddd.id
 left join xxx.lll on xxx.user = bbb.user
 ...
 ...
 group by wd.id, ..., ..., ...

Query B

select
 wd.id,
 ...
 ...
 from
 aaa.bb
 inner join ddd.lll on aa.id = ddd.id
 left join xxx.lll on xxx.user = bbb.user
 ...
 ...
 group by wd.id, ..., ..., ...
  • Answer # 1

    Same as a table if it is simply enclosed in () and treated as a set.

    select *
    from (select ~) as query A
         left join (select ~) as query B
         on Query A.ID = Query B.ID


    However, if you look at the contents, it refers to the same table in two queries, so
    I think that it is more efficient to disassemble and re-assemble.