select * from Gallery.Galleries where Gallery.Galleries.CreatorId in
(select Gallery.Galleries.CreatorId from Gallery.Galleries group by Gallery.Galleries.CreatorId having COUNT(Gallery.Galleries.CreatorId)>1 ) Order by CreatorId
select * from Gallery.Galleries where exists (select Gallery.Galleries.CreatorId from Gallery.Galleries group by Gallery.Galleries.CreatorId having COUNT(Gallery.Galleries.CreatorId)>1)Order by CreatorId
今天进行数据库的优化,本来以为in可以更改为exists可以提高性能但是更改过后查出来的内容不一样,求原因。
第二个语句exists里面 只要有一个creatorid有多行,就会一直有值,所以第二个应该是全都查出来了。
select * from Gallery.Galleries as a where (select count(1) from Gallery.Galleries as b where b.CreatorId=a.CreatorId)>1 order by CreatorId
@飞来飞去: 不好意思我刚刚看了下查询计划,好像两个差不多。。。