sqlserver not exists用法
发布时间:2020-12-12 14:07:01 所属栏目:MsSql教程 来源:网络整理
导读:选择存在于tA表中,但其中name不同于tB表中的数据 select id,name,gender,classId from tA? where? not? exists (select name from tB? where tA.name=tB.name) not in 的写法,同样的效果,但是在大数据量的时候 效率不高 select id,classId from tA? where
选择存在于tA表中,但其中name不同于tB表中的数据 select id,name,gender,classId from tA? where? not? exists (select name from tB? where tA.name=tB.name) not in 的写法,同样的效果,但是在大数据量的时候效率不高 select id,classId from tA? where?name? not? in (select name from tB? where tA.name=tB.name) 或者 select id,classId from tA? where?name? not? in (select name from tB) 如果选取和排除的字段数目相等,还可以用except方法,但是注意它会去除重复的数据(有点类似于union和union all的区别,不过并没有except all这种用法) select name from tA except select name from tB (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |