我整天都被困在这一天,终于找到了一个脚本,除了原始数据之外会删除所有数据,无论如何,我做了必要的更改以允许它使用我的代码,不幸的是它吐出了一个语法错误。我一直在看它约2个小时,我只是看不到它。 无论如何,即时通讯使用MySQL数据库和继承人使用..
DELETE *
FROM music u
JOIN (
SELECT melody, chorus1, chorus2, MIN( id ) AS minid
FROM music
GROUP BY melody, chorus1, chorus2
HAVING (
COUNT( * ) >1
)
) AS dupusers ON u.melody = dupusers.melody
AND u.chorus1 = dupusers.chorus1
AND u.chorus2 = dupusers.chorus2
ORDER BY u.melody, u.chorus1, u.chorus2
WHERE u.id <> minid
我收到以下错误:
1064 - 您的SQL语法出错;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 '* FROM music u JOIN附近(SELECT melody,chorus1,chorus2,MIN(id) AS minid'在第1行
是......
*
FROM music u
JOIN (
SELECT melody, chorus1, chorus2, MIN( id ) AS minid
答案 0 :(得分:1)
因为你在DELETE *
处有语法错误而你在WHERE
子句之后使用了ORDER BY
子句。无需在ORDER BY
查询中使用DELETE
子句,无需尝试:
DELETE u
FROM music u
INNER JOIN (
SELECT melody, chorus1, chorus2, MIN( id ) AS minid
FROM music
GROUP BY melody, chorus1, chorus2
HAVING COUNT(*) >1
) dupusers
ON u.melody = dupusers.melody
AND u.chorus1 = dupusers.chorus1
AND u.chorus2 = dupusers.chorus2
WHERE u.id <> minid;
删除重复项的另一种简单方法是在表格中添加唯一索引,请参阅here。
ALTER IGNORE TABLE music ADD UNIQUE KEY ix1(melody, chorus1, chorus2);