请教left outer join和no in的不同
not In
select * from table where id not in (select top 100 id from table order by id desc)
select * from table left outer join (select top 100 id as tId from table order by id desc) t on t.tId = table.id where t.tId is null
goif OBJECT_ID('tbl')is not nulldrop table tblgocreate table tbl(id int identity(1,1),QQ VARCHAR(10))godeclare @a intset @a=1while @a<=1000000begininsert tblselect ltrim(cast(RAND()*1000000000 as int))set @a=@a+1endselect * from tbl where id not in (select top 100 id from tbl order by id desc)--110万条数据不加任何索引第一次30s,第二次24sselect * from tbl left join (select top 100 id as tId from tbl order by id desc) t on t.tId = tbl.id where t.tId is null--110万条数据不加任何索引第一次24s,第二次24s