2个同样功能的sql结果为什么会不一样
2个sql结果为什么会不一样
功能都是找出表rt里有重复3个字段的记录 (不包含id最小的行) ,
第1个select id from rt
where (typeId,Name,nId) in
(
select typeId,Name,nId
from rt
group by typeId,Name,Id
having count(*) > 1
)
and id not in (
select min(id) from rt
group by typeId,Name,nId
having count(*)>1
);
第2个
select id from rt t where exists ( select 1 from rt where typeId=t.typeId and Name=t.Name and nId=t.nId and id<t.id )
从逻辑上2着数据应该是一样的 (但是事实上2者数据是不一样的 )