The IN operators is used in WHERE condition with SELECT, UPDATE, and DELETE statement.
The IN operator returns values that matches values in a list or subquery.
The IN operators is a shorthand for multiple OR conditions.
Syntax
SELECT column_name
FROM table_name
WHERE column_name IN (value1, value2, value3);
Example — Original Example
Imagine a college has a table called Students:
| RollNo | Name | Course |
|---|---|---|
| 101 | Aarav | BCA |
| 102 | Meera | BBA |
| 103 | Kabir | BCA |
| 104 | Riya | BTech |
| 105 | Arjun | MCA |
Suppose we want to find students studying BCA, MCA, or BTech.
SELECT *
FROM Students
WHERE Course IN ('BCA', 'MCA', 'BTech');
Result
| RollNo | Name | Course |
|---|---|---|
| 101 | Aarav | BCA |
| 103 | Kabir | BCA |
| 104 | Riya | BTech |
| 105 | Arjun | MCA |
The query checks whether the Course value is one of the three values specified inside IN.