是否可以在“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