Hello
What is the use of In operator in SQL Server?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Pravin MoreRank #1,419 · 1.2K reputationPosted Dec 5, 2011, 11:23 PM EST
you can apply condition on multiple values using IN operator.
for e.g:-
select * from account where accountid in (1,2,3,4,10,18)
above query will give alll matching results if account id is in IN condition.
Thanks,
Pravin.
Satyapriya NayakRank #47 · 31.5K reputationPosted Dec 5, 2011, 11:26 PM EST
In SQL, there are two uses of the IN keyword, and this section introduces the one that is related to the WHERE clause. When used in this context, we know exactly the value of the returned values we want to see for at least one of the columns. The syntax for using the IN keyword is as follows:
SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...)
The number of values in the parenthesis can be one or more, with each values separated by comma. Values can be numerical or characters. If there is only one value inside the parenthesis, this commend is equivalent to
WHERE "column_name" = 'value1'
For example, we may wish to select all records for the Los Angeles and the San Diego stores in Table Store_Information,
Table Store_Information
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
San Francisco $300 Jan-08-1999
Boston $700 Jan-08-1999
we key in,
SELECT *
FROM Store_Information
WHERE store_name IN ('Los Angeles', 'San Diego')
Result:
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Thanks
Priya LingeRank #785 · 2.9K reputationPosted Dec 5, 2011, 11:30 PM EST
1.IN Operator :The IN operator allows we to specify multiple values in a WHERE clause.
2.Syntax :
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
3.Example : We have Customer Table in that we have FirstName and LastName.
FirstName LastName
Anil Sharma
Sunil Ranavat
Kunal Varma
SELECT * FROM Customer
WHERE LastName IN ('Sharma','Ranavat')
OutPut :
FirstName LastName
Anil Sharma
Sunil Ranavat
Hope this will help you.
Thanks.
Prashant ChaudharyRank #1,151 · 1.6K reputationPosted Dec 6, 2011, 1:08 AM EST