SQL SERVER 不支持多字段的IN 和 NOT IN 但是ORACLE是支持的。
表a 有字段:a, b, c还可能有其他字段。
表b 有字段:a,b,c 还可能有其他字段。
create table a (
a varchar(100),
b varchar(100),
c varchar(100)
)
create table b (
a varchar(100),
b varchar(100),
c varchar(100)
)
insert a values ('1','a','甲');
insert a values ('2','b','乙');
insert a values ('3','c','丙');
insert b values ('1','a','甲');
insert b values ('2','b','乙');
insert b values ('3','c','丙');
执行该语句:select * from a where (a,b) IN (select a,b from b);
结果:
消息 102,级别 15,状态 1,第 2 行
',' 附近有语法错误。
语句改成 exists :
select * from a
where exists (select 1 from b
where a.a=b.a and a.b = b.b
);
执行结果:
所以:在sqlserver 中要使用多字段的in 或者是 not in 应该改为 exists 或者 not exists 语句。
SQL SERVER 不支持多字段的IN 和 NOT IN
转载本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
sql server不支持存放繁体 不支持的sql版本
当我们在做MS-sqlserver数据库部署的时候,服务器里的数据库版本和开发者笔记本里的版本不兼容,会遇到这种问题,附加时,提示版本为XXX,无法打开,支持XXX版本。 &nb
sql server不支持存放繁体 数据库 Server SQL