In与Exists这两个函数是差不多的,但由于优化方案不同,通常NOT Exists要比NOT IN要快,因为NOT EXISTS可以使用结合算法二NOT IN就不行了,而EXISTS则不如IN快,因为这时候IN可能更多的使用结合算法。
create table #tempTable1
(
argument1 nvarchar(50),
argument2 varchar(20),
argument3 datetime,
argument4 int
);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher001','13023218757',GETDATE()-1,1);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher002','23218757',GETDATE()-2,2);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher003','13018757',GETDATE()-3,3);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher004','13023257',GETDATE()-4,4);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher005','13023218',GETDATE()-5,5);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher006','13023218',GETDATE()-6,6);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher007','13023218',GETDATE()-7,7);
insert into #tempTable1(argument1,argument2,argument3,argument4)
values('preacher008','13023218',GETDATE()-8,8);
create table #tempTable2
(
argument1 nvarchar(50),
argument2 varchar(20),
argument3 datetime,
argument4 int
);
insert into #tempTable2(argument1,argument2,argument3,argument4)
values('preacher001','13023218757',GETDATE()-1,1);
insert into #tempTable2(argument1,argument2,argument3,argument4)
values('preacher0010','23218757',GETDATE()-10,10);
insert into #tempTable2(argument1,argument2,argument3,argument4)
values('preacher003','13018757',GETDATE()-3,3);
insert into #tempTable2(argument1,argument2,argument3,argument4)
values('preacher004','13023257',GETDATE()-4,4);
insert into #tempTable2(argument1,argument2,argument3,argument4)
values('preacher009','13023218',GETDATE()-9,9);