oracle8.1.6 select * from (select tc.category_id, tc.name as category, count(tt.ticket_id) as total, sum(decode(lower(state),'active',1,0)) as active, sum(decode(lower(state),'suspended',1,0)) as suspended, sum(decode(lower(state),'canceled',1,0)) as canceled, sum(decode(lower(state),'finished',1,0)) as finished from ttracker_categories tc, ttracker_tickets tt, wf_cases wfc where tc.package_id = :package_id and tt.category_id = tc.category_id and tt.ticket_id = wfc.object_id [ad_dimensional_sql $dimensional] group by tc.category_id, tc.name union all select tc1.category_id, tc1.name as category, 0 as total, 0 as active, 0 as suspended, 0 as canceled, 0 as finished from ttracker_categories tc1 where tc1.package_id = :package_id and not exists (select tt1.ticket_id from ttracker_tickets tt1 where tt1.category_id = tc1.category_id [ad_dimensional_sql $dimensional])) [ad_order_by_from_sort_spec $orderby $table_def] creation_date + 365 > sysdate creation_date + 90 > sysdate creation_date + 30 > sysdate