编程错误导致在此表中多次插入相同的行。我知道架构中的约束可能会阻止插入。
我正在尝试找到一种方法来删除每个回合/数字对中除最新(最高 ID)行以外的所有行。我当然可以编写脚本,但我想知道是否有一种方法可以在纯 SQL 中执行此操作?
最佳答案
通常你可以这样做:
delete from your_table
where id not in
(
select max(id) from your_table
group by user, round, date, number
)
在 MySQL 中,您不能从您正在选择的同一个表中删除。但是你可以像这样用另一个子查询来欺骗 MySQL:
delete from your_table
where id not in
(
select * from
(
select max(id) from your_table
group by user, round, date, number
) x
)
关于mysql - 重复删除 mySQL 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18152796/