Query SELECT DISTINCT(a.mrepc_no), a.name, a.contact_person, a.company_no, a.office_telephone, a.office_fax, a.email, a.website, b.powdered, b.powder_free, c.ee_no, b.powdered2, b.powder_free2, d.bimg, d.type, e.state, e.flag FROM company_details a, company_product b, companies_ee c, business_type d, state e WHERE a.mrepc_no = b.mrepc_no AND b.mrepc_no = c.mrepc_no AND b.business_type = d.type_id AND a.state_id = e.state_id AND (b.business_type = 1 OR b.business_type = 2) AND (a.not_active IS NULL OR a.not_active = 0) AND b.smg='1' group by a.name ORDER BY a.name ASC failed