mysql删除重复数据,以学号为准,没有设置主键。

一个学生信息表,没有主键
表名
taun_yuan_student
内容
student_id student_name student_class student_crad student_book
以student_id 为准,删除重复数据,只保留一条信息

我看了很多的mysql语句,很多都不能实现,而且表不能设置主键,不要问为什么,问就是设置了会出bug
希望有人帮忙写一条语句解答

换表即可,思路如下新建表并添加这个表里的数据(不重复),删除原有表,将新的表重命名为原来的表名,执行sql命令如下

create table table1(student_id,student_name,student_class,student_crad,student_book) 
as select  DISTINCT  `student_id`,student_name,student_class,student_crad,student_book from taun_yuan_student;

drop table taun_yuan_student;

alter table table1 rename to taun_yuan_student;

1、首先给表加上自增字段:

alter table taun_yuan_student add column id int auto_increment not null, add primary key(id);

2、然后进行过滤删除:

 delete from taun_yuan_student where id not in(
select min(id) from taun_yuan_student group by student_id
)

如果 重复的数据是一模一样的, 用 distinct 重建表比较快

如果student_id 一样, 但 student_name或者其他字段不一样,如何取舍?

student_id是唯一不重复的嘛?student_crad 是学号?