首页 > 代码库 > 多表删除

多表删除

删除重复的记录

mysql> SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING coun
t(goods_name) >= 2;
+----------+-----------------------+
| goods_id | goods_name |
+----------+-----------------------+
| 18 | HMZ-T3W 头戴显示设备 |
| 19 | 商务双肩背包 |
+----------+-----------------------+

mysql> DELETE t1 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;
Query OK, 2 rows affected (0.05 sec)

 

多表删除