SQL IN Operator

IN operator is used to match the value from the list of values.
It is a short form of multiple OR condition.

In SELECT Statement

Syntax:-


SELECT column(s) 
FROM table_name 
WHERE column
IN (value1, value2.......valueN)

Example:- Suppose we have employees table which has 7 records


+----+------------+-----------+----------------+-----------+
| id | first_name | last_name | email          | country   |
+----+------------+-----------+----------------+-----------+
|  1 | John       | Tailor    | john@abc.com   | USA       |
|  2 | Rom        | Tailor    | rom@abc.com    | USA       |
|  3 | Andrew     | Symonds   | andrew@abc.com | Australia |
|  4 | Miacle     | Tailor    | miacle@abc.com | Australia |
|  5 | Sachin     | Tendulkar | sachin@abc.com | India     |
|  6 | Virat      | Kohli     | virat@abc.com  | India     |
|  7 | rohit      | NULL      | rohit@abc.com  | India     |
Q:- Find the employees that have last_name Tendulkar OR Kohli

SELECT * FROM employees
WHERE last_name IN ('Tendulkar', 'Kohli');

Output:-


+----+------------+-----------+----------------+---------+
| id | first_name | last_name | email          | country |
+----+------------+-----------+----------------+---------+
|  5 | Sachin     | Tendulkar | sachin@abc.com | India   |
|  6 | Virat      | Kohli     | virat@abc.com  | India   |
+----+------------+-----------+----------------+---------+
2 rows in set (0.00 sec)

SQL IN Operator – Interview Questions

Q 1: What is IN used for?
Ans: IN checks if a value matches any value in a list.
Q 2: Is IN better than multiple OR conditions?
Ans: Yes, it improves readability.
Q 3: Can IN use subqueries?
Ans: Yes.
Q 4: Does IN allow NULL values?
Ans: NULLs require special handling.
Q 5: Can IN be used with NOT?
Ans: Yes, as NOT IN.

SQL IN Operator – Objective Questions (MCQs)

Q1. What does the IN operator do?






Q2. Which query is correct?






Q3. IN operator is an alternative to:






Q4. IN can be used with:






Q5. IN improves query readability compared to:






Related SQL IN Operator Topics