0

Is it valid to combine Oracle inner and outer joins in the same query a la:

select b.col1, c.col2, sum(d.col1), sum(e.col1) from 
a  
inner join b on a.xxx = b.xxx 
inner join c on a.yyy = c.yyy 
left join d on b.aaa = d.aaa and c.bbb = d.bbb
left join e on b.aaa = e.bbb and c.aaa = e.bbb
group by b.col1, c.col2
user272735
  • 10,473
  • 9
  • 65
  • 96
Marcus Leon
  • 55,199
  • 118
  • 297
  • 429

3 Answers3

0

Yes, you can combine inner, left and right joins the way you deem fit in the query. Just make sure that you understand the implications of inner, left and outer joins. Couple of blogs describe joins nicely: http://blog.codinghorror.com/a-visual-explanation-of-sql-joins/ and http://www.codeproject.com/Articles/33052/Visual-Representation-of-SQL-Joins

zedfoxus
  • 35,121
  • 5
  • 64
  • 63
0

The outer join nulls are ignored in your sum(d.col1) and sum(e.col1) values.

Why SUM(null) is not 0 in Oracle?

If alternate default values are needed for your null outer join results, consider NVL and similar.

Sum columns with null values in oracle

Community
  • 1
  • 1
Shep
  • 638
  • 3
  • 15
0

Please try this, All non aggregated columns should be in group by clause.

 select b.col1, c.col2, sum(d.col1), sum(e.col1) from 
    a  
    inner join b on a.xxx = b.xxx 
    inner join c on a.yyy = c.yyy 
    left join d on b.aaa = d.aaa and c.bbb = d.bbb
    left join e on b.aaa = e.bbb and c.aaa = e.bbb
    group by b.col1, c.col2
Ruelos Joel
  • 2,209
  • 3
  • 19
  • 33