在执行 DELETE 语句之前,先使用 SELECT 进行验证:
SELECT t1.n_id, t1.n_title
FROM sea_news t1
INNER JOIN sea_news t2
WHERE t1.n_title = t2.n_title
AND t1.n_id > t2.n_id;
删除重复记录的正确 SQL:
DELETE t1
FROM sea_news t1
INNER JOIN sea_news t2
WHERE t1.n_title = t2.n_title
AND t1.n_id > t2.n_id;
验证结果:再次执行查找重复的 SQL,确保没有多余的重复数据:
SELECT n_title, COUNT(*) as count
FROM sea_news
GROUP BY n_title
HAVING COUNT(*) > 1;
评论(0)