我在删除具有最高用户 ID 的重复行时遇到了一些问题,想知道如何使用与 3.22.0 版兼容的方法在 SQLite 中实现这一点?
我可以通过运行以下语句来识别所有重复的行:
SELECT
code, issue, COUNT(*)
FROM
Data
GROUP BY
code, issue
HAVING
COUNT(*) > 1
我试过使用:
delete from Data t1
where exists (select 1 from Data t2
where t1.code = t2.code and t1.issue = t2.issue
and t1.id < t2.id);
这让我在 t1
附近出现语法错误。我做错了什么?
答案 0 :(得分:2)
我认为 sqlite 不支持 delete
的别名。
尝试以下查询:
delete from Data
where exists (select 1 from Data t2
where data.code = t2.code and data.issue = t2.issue
and data.id < t2.id);