执行DELETE操作前可先执行如下SELECT语句,有助于理解:
SELECT * FROM tdb_goods AS t1
LEFT JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING COUNT(goods_name)>=2) AS t2
ON t1.goods_name=t2.goods_name
WHERE t1.goods_id>t2.goods_id\G
SELECT * FROM tdb_goods AS t1
LEFT JOIN (SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING COUNT(goods_name)>=2) AS t2
ON t1.goods_name=t2.goods_name
WHERE t1.goods_id>t2.goods_id\G
主键唯一PRIMARY用于ID时就已经自动递增了所以每个赋予的值都是唯一的,唯一约束UNIQUE就是你去赋值的时候被约束不能赋值已存在的值,应该可以这样理解吧。。。
2017-08-30