加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 具有多个字段的sql server-IN子句

发布时间:2020-12-12 16:15:30 所属栏目:MsSql教程 来源:网络整理
导读:是否可以在“IN”子句中包含多个字段?类似于以下内容 select * from userwhere code,userType in ( select code,userType from userType ) 谢谢 我使用ms sql server 2008 – 编辑:我知道这可以通过连接和存在实现(谢谢你的答案),我只是想知道是否可以完成
是否可以在“IN”子句中包含多个字段?类似于以下内容
select * from user
where code,userType in ( select code,userType from userType )

谢谢

我使用ms sql server 2008

编辑:我知道这可以通过连接和存在实现(谢谢你的答案),我只是想知道是否可以完成与IN子句…

解决方法

不是你发布的方式.您只能返回单个字段或类型为IN工作.

从MSDN(IN):

test_expression [ NOT ] IN 
    ( subquery | expression [,...n ]
    ) 

subquery - Is a subquery that has a result set of one column. 
           This column must have the same data type as test_expression.

expression[,... n ] - Is a list of expressions to test for a match. 
                       All expressions must be of the same type as 
                       test_expression.

而不是IN,您可以使用两个字段的JOIN:

SELECT U.* 
FROM user U
  INNER JOIN userType UT
    ON U.code = UT.code
    AND U.userType = UT.userType

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读