SQL Server - IN clause with multiple fields

后端 未结 8 704
野性不改
野性不改 2020-12-20 11:42

Is it possible to include in a IN clause multiple fields? Something like the following:

select * from user
where code, userType in ( select code         


        
8条回答
  •  旧时难觅i
    2020-12-20 12:07

    Only with something horrific, like

    select * from user
    where (code + userType) in ( select code + userType from userType )
    

    Then you have to manage nulls and concatenating numbers rather than adding them, and casting, and a code of 12 and a usertype of 3 vs a code of 1 and a usertype of 23, and...

    So there ya go: a solution that doesn't use joins or exists.. and a bunch of reasons why you shouldn't use it ;)

提交回复
热议问题