OR Operator works togther with WHERE Clause, OR operator display records when any condition is met. OR Operator is a part of the logical operator.
In SELECT Statement
Syntax:-
SELECT column(s)
FROM table_name
WHERE condition1 OR condition2..
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 | clerk | 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 |
Now, we have to get the employees which country has INDIA OR USA.
SELECT * FROM employees where country='India' OR country='USA';
Output:-
+----+------------+-----------+----------------+---------+
| id | first_name | last_name | email | country |
+----+------------+-----------+----------------+---------+
| 1 | John | Tailor | john@abc.com | USA |
| 2 | Rom | Tailor | rom@abc.com | USA |
| 5 | Sachin | Tendulkar | sachin@abc.com | India |
| 6 | Virat | Kohli | virat@abc.com | India |
| 7 | rohit | NULL | rohit@abc.com | India |
+----+------------+-----------+----------------+---------+
5 rows in set (0.00 sec)
SQL OR Operator – Interview Questions
Q 1: What does the OR operator do?
Ans: OR returns true if any condition is true.
Q 2: Can OR be used with SELECT?
Ans: Yes, inside the WHERE clause.
Q 3: Can OR return duplicate rows?
Ans: Yes, if conditions overlap.
Q 4: Is OR slower than AND?
Ans: It may be slower depending on conditions.
Q 5: Can OR be combined with AND?
Ans: Yes, using parentheses.
SQL OR Operator – Objective Questions (MCQs)
Q1. What does the OR operator do in SQL?
Q2. OR operator is used to combine:
Q3. Which query uses OR correctly?
Q4. OR operator returns FALSE when:
Q5. OR operator is commonly used with: