Let's say I want to first select rows which have download_link the same. Then, I want to keep the one that has lowest primary id, and throw away the rest.
Is there an easy SQL statement for this? Would this work?
delete from mytable
where id not in
(select min(id)
from mytable
group by download_link);
解决方案
You don't need temporary tables or subqueries. You can do it with a simple join:
DELETE t0
FROM mytable AS t0
JOIN mytable AS t1 ON t1.download_link=t0.download_link AND t1.id
That is, “delete every row for which there is another row with the same link and a lower ID”.