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.
Written by Shaikh Abdul Shahid
A Full-Stack Developer with experience in PHP, Laravel, JavaScript, and React.
Founder of Online Learner, sharing practical knowledge and programming tutorials.
Building and maintaining real-world web applications since 2017.
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
