Explain OR Operator In SQL
The OR
operator in SQL is used to combine multiple conditions in a WHERE
clause. If any of the conditions separated by OR
evaluates to true, the row will be included in the results.
Here's a simple example to illustrate how the OR
operator works:
Example Scenario
Suppose you have a table named Employees
with the following data:
EmployeeID | Name | Department | Salary |
---|---|---|---|
1 | Alice | HR | 60000 |
2 | Bob | IT | 70000 |
3 | Charlie | HR | 80000 |
4 | David | Sales | 55000 |
5 | Eva | IT | 65000 |
Query
If you want to find employees who are either in the "HR" department or have a salary greater than 60000, you would write a query like this:
SELECT *
FROM Employees
WHERE Department = 'HR'
OR Salary > 60000;
Output
The result of this query would be:
EmployeeID | Name | Department | Salary |
---|---|---|---|
1 | Alice | HR | 60000 |
2 | Bob | IT | 70000 |
3 | Charlie | HR | 80000 |
5 | Eva | IT | 65000 |
Explanation:
- Alice is included because she is in the HR department.
- Bob, Charlie, and Eva are included because their salaries are greater than 60000.
The OR
operator ensures that if any of the specified conditions are met, the row will be included in the results.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Copyright 2023-2025 © All rights reserved.