About deleting duplicate data in mysql database

  • For small issues and big details, refer to the article:
  • The focus is on the second link. The idea of ​​the first link is good, but the second method and summary are better.
  • https://www.cnblogs.com/luyingfeng/p/5772262.html
  • https://www.cnblogs.com/liyue-sqsf/p/9076902.html

The table is as follows:
Insert picture description here

DELETE from S_score2 where id IN (
-- 	这里再加 一个 select 语句,因为 
--  警告:不能根据本表的查询结果来更新本表的数据,所以给表起个别名
	select * from (
		SELECT id from S_score2 
		where 
		(姓名, 课程) in
		(SELECT 姓名, 课程 FROM S_score2 GROUP BY 姓名, 课程 HAVING COUNT(*) > 1)
		and 
		id not in (SELECT min(id) from S_score2 GROUP BY 姓名, 课程 HAVING count(*)> 1)
) as stu_score

);
to sum up:

This question seems simple. I thought about many solutions, and I thought about it for a long time~ I won’t say much. Everyone, look at the two links carefully, and it’s best to implement them in your own way.
the end.

Guess you like

Origin blog.csdn.net/pythonstrat/article/details/111598992