Query SELECT count(distinct a.mrepc_no) as total, b.item as product_name ,b.item_id FROM company_product_exp_upd a, igcat_item_upd b, company_details c, company_product d WHERE a.mrepc_no = c.mrepc_no AND c.mrepc_no = d.mrepc_no AND (c.not_active IS NULL OR c.not_active = 0) AND a.igcat_id = '012' AND c.state_id = 'JH' AND a.item_id = b.item_id group by a.item_id order by b.item failed