Skip to content
Advertisement

‘In’ clause in SQL server with multiple columns

I have a component that retrieves data from database based on the keys provided. However I want my java application to get all the data for all keys in a single database hit to fasten up things. I can use ‘in’ clause when I have only one key.

While working on more than one key I can use below query in oracle

which is similar to writing

and

together

However, this concept of using ‘in’ clause as above is giving below error in ‘SQL server’

ERROR:An expression of non-boolean type specified in a context where a condition is expected, near ','.

Please let know if their is any way to achieve the same in SQL server.

Advertisement

Answer

This syntax doesn’t exist in SQL Server. Use a combination of And and Or.

(In this case, you could make it shorter, because value_type is compared to the same value in both combinations. I just wanted to show the pattern that works like IN in oracle with multiple fields.)


When using IN with a subquery, you need to rephrase it like this:

Oracle:

SQL Server:

There are other ways to do it, depending on the case, like inner joins and the like.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement