【发布时间】:2015-10-30 16:47:31
【问题描述】:
我在mysql中有这个表叫ts1
+----------+-------------+---------------+
| position | email | date_of_birth |
+----------+-------------+---------------+
| 3 | NULL | 1987-09-03 |
| 1 | NULL | 1982-03-26 |
| 2 | Sam@gmail | 1976-10-03 |
| 2 | Sam@gmail | 1976-10-03 |
+----------+-------------+---------------+
我想使用 ALTER IGNORE 删除相等的行。
我试过了
ALTER IGNORE TABLE ts1 ADD UNIQUE INDEX inx (position, email, date_of_birth);
和
ALTER IGNORE TABLE ts1 ADD UNIQUE(position, email, date_of_birth);
在这两种情况下我都会得到 p>
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 'IGNORE TABLE ts1 ADD UNIQUE(position, email, date_of_birth)' at line 1
我正在使用 mySQL 5.7.9。有什么建议吗?
【问题讨论】:
-
好的,你能指出最有效的替代方案吗?
-
可能需要添加 PK,因此当您手动删除它们(或通过一些保留 min() 策略)时,您有一行或多行要定位。然后当一切都清理干净后,将那个独特的复合材料放在那里
-
创建一个带有 DISTINCT 结果的新索引表。
-
是的,更容易,正如草莓所说,see pastie
标签: mysql