码迷,mamicode.com
首页 > 其他好文 > 详细

多表删除

时间:2017-03-27 19:39:19      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:having   _id   row   span   from   多表   --   strong   删除   

删除重复的记录

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)

 

多表删除

标签:having   _id   row   span   from   多表   --   strong   删除   

原文地址:http://www.cnblogs.com/toudoubao/p/6628225.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!