与插入相反 - 删除重复项

opposite of insert into - removing duplicates

我是 Sql 的新手,所以请多多包涵。我有 运行 查询以下查询:

INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');

然而,不小心我运行它两次。我想删除重复项。怎么做到的?

我试过了

 INSERT INTO adhoc_dt.`table` (id, name) VALUES(53098974, 'John');

但出现错误:

SQL ERROR [1064][42000]: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

如果您的 table 名称包含保留字的特殊字符,那么您应该用反引号将 table 名称括起来:

 `table`

但是看你的问题,table名字好像是:

`adhoc_dt.`table` 

在这种情况下,删除的正确语法是:

DELETE FROM  adhoc_dt.`table`
WHERE id =  53098974 AND name =  'JOHN'

但通过这种方式,您可以删除所有具有以下内容的行:

 id =  53098974 AND name =  'JOHN'

您必须按照步骤进行

  • t运行分类table
  • 对 ID 应用唯一约束
  • 运行 插入脚本