DELETE m FROM `mall_commodity_launch_codev2` m WHERE EXISTS ( SELECT sCode, nCmdtId FROM ( SELECT t.`s_code` AS sCode, t.`n_commodity_id` AS nCmdtId, COUNT(1) NUM FROM `mall_commodity_launch_codev2` t WHERE 1=1 GROUP BY t.`n_commodity_id`,t.`s_code` HAVING NUM > 1) tt WHERE tt.sCode = m.`s_code` AND tt.nCmdtId = m.`n_commodity_id`)
在sqlyog中执行,不报错,但是也没有删除效果:没有删掉数据,一直显示执行中……
解决方案
20
mysql的delete语句好像是不支持子查询的。
不过,你可以修改成 关联查询,相似于:
不过,你可以修改成 关联查询,相似于:
DELETE m FROM `mall_commodity_launch_codev2` m, ( SELECT sCode, nCmdtId FROM ( SELECT t.`s_code` AS sCode, t.`n_commodity_id` AS nCmdtId, COUNT(1) NUM FROM `mall_commodity_launch_codev2` t WHERE 1=1 GROUP BY t.`n_commodity_id`,t.`s_code` HAVING NUM > 1) tt WHERE tt.sCode = m.`s_code` AND tt.nCmdtId = m.`n_commodity_id`