in command in SQL
What is the use of in command in SQL.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Sep 11, 2012, 10:34 AM
The IN operator allows you to specify multiple values in a WHERE clause.
SQL IN Syntax
FROM table_name
WHERE column_name IN (value1,value2,...)
IN Operator Example
The "Persons" table:
Now we want to select the persons with a last name equal to "Hansen" or "Pettersen" from the table above.
We use the following SELECT statement:
WHERE LastName IN ('Hansen','Pettersen')
The result-set will look like this:
Please refer the below link
http://www.w3schools.com/sql/sql_in.asp
Thanks
Sukesh MarlaPosted Sep 11, 2012, 8:06 AM
IN operator allows you to specify multiple values in a WHERE clause.
SELECT column_name(s)
FROM table_name
WHERE column_name IN (value1,value2,...)
Check this is correct answer if it helped.
nallyaPosted Sep 11, 2012, 8:01 AM
The IN function helps reduce the need to use multiple OR conditions.
The syntax for the IN function is:
SELECT columns
FROM tables
WHERE column1 in (value1, value2, .... value_n);
This SQL statement will return the records where column1 is value1, value2..., or value_n. The IN function can be used in any valid SQL statement - select, insert, update, or delete.
Example #1:
The following is an SQL statement that uses the IN function:
This would return all rows where the supplier_name is either IBM, Hewlett Packard, or Microsoft. Because the * is used in the select, all fields from the suppliers table would appear in the result set.
It is equivalent to the following statement:
As you can see, using the IN function makes the statement easier to read and more efficient.
Example #2:
You can also use the IN function with numeric values.
This SQL statement would return all orders where the order_id is either 10000, 10001, 10003, or 10005.
It is equivalent to the following statement:
Example #3 - using "NOT IN":
The IN function can also be combined with the NOT operator.
For example,
This would return all rows where the supplier_name is neither IBM, Hewlett Packard, or Microsoft. Sometimes, it is more efficient to list the values that you do not want, as opposed to the values that you do want.