$result = mysql_query(" select yr , mth , sum(main_subtot) as main_count , sum(pop_subtot) as pop_count from ( select year(add_date) as yr , month(add_date) as mth , count(*) as main_subtot , NULL as pop_subtot from clogsyn_track_main where user_id = $uid group by year(add_date) , month(add_date) union all select year(add_date) , month(add_date) , NULL , count(*) from clogsyn_track_pop where user_id = $uid group by year(add_date) , month(add_date) ) as data group by yr , mth ");