SQL Select In
SQL IN is an operator used in a SQL query to help reduce the need to use multiple SQL “OR” conditions. The IN operator allows you to specify multiple values in a WHERE clause. It is used in SELECT, INSERT, UPDATE, or DELETE statements.
Example:
Expression IN (value 1, value 2 … value n);
We have a table called Employee with four columns:
Take an example with character values.
SELECT * FROM Employee WHERE Emp_Name IN (Ankit, Bheem, Sumit);
The result will be shown as this table:
The result will be shown as this table:
SELECT * FROM Employee WHERE Emp_Salary IN (25000, 30000, 40000);
The result will be shown as this table:
Course Video
NOTE: Practice below questions on site editor.
1. Write SQL Query to get all the records from Person_Person table whose BusinessEntityID is 1, 5 and 10 using IN operator.
Table: (Person_Person)-(3 row count)
2. Write SQL Query to get all the records from Production_Culture table where Name is ‘Arabic’,
‘English’,’Thai’ using IN operator
Table: (Production_Culture)-(3 row count)
3. Make a SQL Query to find Name, ShiftID from HumanResource_Shift table where Name is (Day, Night, Evening) using IN operator.
Table: (HumanResource_Shift)-(3 row count)
4. Write SQL Query to get all the columns from HumanResources_EmployeePayHistory table where BusinessEntityID is (1,2,3,4) and Rate is less than 50 Using IN operator.
Table: (HumanResources_EmployeePayHistory)-(4 row count)
5. Write a SQl Query to get all the records from HumanResources_EmployeePayHistory table where BusinessEntityID is (1,2,3,4,5,6) and Rate is grater than 50 Using IN operator.
Table : (HumanResources_EmployeePayHistory)-(6 row count)
6. Write an SQL query to retrieve all columns from the ‘Employee’ table for employees with BusinessEntityID is 21, 22, 23, 24, 25, 26 and MaritalStatus equal to ‘M’. [OUTPUT: 4 ROWS]
7. Write an SQL query to retrieve all columns from the ‘PurchaseOrderDetail’ table where the OrderQty is 550 and 4. [output: 46 rows]
8. Write an SQL query to retrieve all columns from the ‘Purchasing_PurchaseOrderHeader’ table where the EmployeeID is 261, 251 and subtotal is greaterthan 1000. [ OUTPUT: 11 ROWS]
9. Write an SQL query to retrieve all columns from the ‘SalesOrderDetail’ table where the SalesOrderID is either 43659, 43665, or 43668, and the UnitPrice is greater than 100.[ OUTPUT: 27 ROWS ]
10. Write an SQL query to retrieve all columns from the ‘SalesReason’ table where the ReasonType is ‘other’ and ‘promotion’.[OUTPUT: 6 ROWS ]
YouTube Reference :
1) SQL Select In in Hindi/Urdu
2) SQL Select In in English