1. 采用not exists 执行速度快
delete from T_AD where not exists (select 1 from T_AD_PLAY where T_AD.N_CODE =T_AD_PLAY.N_CODE )
2. 采用not in 执行速度慢
Delete From T_AD Where N_AD Not In(Select N_AD From T_AD_PLAY)
T_AD表中的哪个字段的记录在T_AD_PLAY表中的哪个字段的记录中不存在?
假设是删除T_AD表中N_CODE在T_AD_PLAY表中的N_CODE不存在的记录吧
delete from T_AD where T_AD.N_CODE not in (select T_AD_PLAY.N_CODE from T_AD_PLAY)
delete from T_AD
where T_AD.N_CODE
not in (select T_AD.N_CODE from T_AD
where T_AD.N_CODE =T_AD_PLAY.N_CODE )
delete from T_AD
where not exists (select 1 from T_AD_PLAY where T_AD.N_CODE =T_AD_PLAY.N_CODE )
这才是快的
delete from T_AD where T_AD.N_CODE NOT EXISTS (SELECT N_AD FROM T_AD_PLAY)