SQL multiple columns in IN clause

后端 未结 6 2002
情书的邮戳
情书的邮戳 2020-11-27 04:15

If we need to query a table based on some set of values for a given column, we can simply use the IN clause.

But if query need to be performed based on multiple col

6条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 05:02

    Ensure you have an index on your firstname and lastname columns and go with 1. This really won't have much of a performance impact at all.

    EDIT: After @Dems comment regarding spamming the plan cache ,a better solution might be to create a computed column on the existing table (or a separate view) which contained a concatenated Firstname + Lastname value, thus allowing you to execute a query such as

    SELECT City 
    FROM User 
    WHERE Fullname in (@fullnames)
    

    where @fullnames looks a bit like "'JonDoe', 'JaneDoe'" etc

提交回复
热议问题