为什么t1.goods_id大于t2.goods_id就能删除两个id大的了?
根据老师的删除代码可以得出查询语句如下
select t1.goods_name,t1.goods_id,t2.goods_name as goods1_name from tdb_goods as t1 LEFT JOIN (SELECT goods_id,goods_name from tdb_goods GROUP BY goods_name HAVING COUNT(goods_id)>=2) as t2 ON t1.goods_name=t2.goods_name where t1.goods_id>t2.goods_id,结果如下,确实是两条记录:
当我去掉WHERE条件后,即:
select t1.goods_name,t1.goods_id,t2.goods_name as goods1_name,t2.goods_id as goods1_id from tdb_goods as t1 LEFT JOIN (SELECT goods_id,goods_name from tdb_goods GROUP BY goods_name HAVING COUNT(goods_id)>=2) as t2 ON t1.goods_name=t2.goods_name;
结果是有24条记录.
那么t1.goods_id>t2.goods_id难道t2为null的是不进行比较直接排除吗?
如果比较的话应该是留有22条记录的吧?