Query2 SELECT count(DISTINCT a.mrepc_no) as totaluser, c.state, c.state_id, c.flag, d.item FROM company_product_exp_upd a, company_details b, state c, igcat_item_upd d, company_product e WHERE a.mrepc_no = b.mrepc_no and b.mrepc_no = e.mrepc_no AND (b.not_active IS NULL OR b.not_active = 0) AND a.igcat_id = '007' AND a.item_id = d.item_id AND e.business_type = '1' AND b.state_id = c.state_id group by c.state order by d.item failed