MySQL–操作数据表6:多表删除

-- INSERT ... SELECT实现复制

INSERT tdb_goods(goods_name,cate_id,brand_id) SELECT goods_name,cate_id,brand_id FROM tdb_goods WHERE goods_id IN (19,20);

-- 查找重复记录

SELECT goods_id,goods_name FROM tdb_goods GROUP BY goods_name HAVING count(goods_name) >= 2;

-- 删除重复记录

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;