删除重复数据

一个表中由于某种原因有了重复数据,需要把重复数据删除,重复的只留一份。

DELETE FROM sim_article_candidate
WHERE third_articleid IN (
		SELECT third_articleid
		FROM (
			SELECT third_articleid
			FROM sim_article_candidate
			WHERE imp_date = 20200601
			GROUP BY third_articleid
			HAVING COUNT(third_articleid) > 1
		) a
	)
	AND flowid NOT IN (
		SELECT flowid
		FROM (
			SELECT MAX(flowid) AS flowid
			FROM sim_article_candidate
			WHERE imp_date = 20200601
			GROUP BY third_articleid
			HAVING COUNT(third_articleid) > 1
		) b
	);

Last updated