GOT error for the following query in MYSQL(version5.1)
SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4)
from(
select year,month,fact_1,fact_2,0 as fact_3,0 as fact_4 from table_1
intersect
select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2
) as combined_table
group by month,year
Error Line with code#1064:-
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2 ) as ct g' at line 5
but following query was giving desired Result:-
SELECT year,month,sum(fact_1),sum(fact_2),sum(fact_3),sum(fact_4)
from(
select year,month,fact_1 ,fact_2,0 as fact_3,0 as fact_4 from table_1
union
select year,month,0 as fact_1,0 as fact_2,fact_3,fact_4 from table_2
) as ct
group by month,year
Can anybody tell what error i am committing? can Anybody help me to understand the root cause behind the Problem.