Решение одним запросом:

DELETE o FROM table as o
INNER JOIN (
    SELECT element_id, MAX(id) as max_id
    FROM table 
    GROUP BY element_id 
    HAVING COUNT(*) > 1
) as r ON o.element_id = r.element_id
WHERE o.id < r.max_id