SQL OR Operator

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)