UPDATE agents SET is_active = 1 WHERE (select count(*) from advertises where advertises.agent_id = agents.id) > 1 and is_active = 2