I want to left join 2 tables.
So all attributes of left table should be shown in result table, no matter if it can join with other table or not.
When I do the follwing, I dont get the expected result
week_table:
date kw note
---------- -- ----
2012-04-01 0 NULL
2012-04-02 0 NULL
fact_table:
id number_of_application number_of_cluster number_of_jvm number_of_node number_of_was fk_wasversion fk_date fk_domain fk_osname fk_osarch fk_osversion fk_stage
-- --------------------- ----------------- ------------- -------------- ------------- ------------- ---------- --------- --------- --------- ------------ --------
1 114 8 80 18 18 6.0 2012-04-01 domain1 Linux sparc 2 stage1
2 114 8 80 18 18 6.0 2012-04-02 domain1 Linux sparc 2 stage1
3 114 8 80 18 18 6.0 2012-04-01 domain1 AIX sparc 2 stage1
4 114 8 80 18 18 6.0 2012-04-02 domain1 Solaris sparc 2 stage1
When I do this:
select
w.date,
coalesce(sum(f.number_of_was), 0)
from
week_table w
left join fact_table f on (w.date = f.fk_date)
where f.fk_osname = "AIX"
group by w.date;
I only get :
date coalesce(sum(f.number_of_was), 0)
---------- ---------------------------------
2012-04-01 18
Expected:
date coalesce(sum(f.number_of_was), 0)
---------- --------------------------------
2012-04-02 18
Does someone know why?
Best Regards
Move the criteria on the outer joined table from the WHERE clause to the ON clause: