为什么删除的时候我没叫WHERE 后面的语句导致整个数据表记录都被删除了???
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;
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;
2019-09-07
可能是因为左连接 有的数据虽然没有满足条件(t1.goods_name=t2.goods_name) 但数据还是存在的
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;
得到的表大概如下
t1.goods_id t1.goods_name t2.goods_id t2.goods_name
1 商务背包 1 商务背包
2 商务背包 1 商务背包
3 笔记本 (没有数据) (没有数据)
所以删除的时候就把整张表删了,用右连接应该不会出现这种情况
举报