The OR operator is a logical operator used to combine conditions where at least one condition must evaluate to TRUE. It is useful when a query should return records matching one condition, another condition, or both.
Business requirements often provide alternatives. For example, an analyst may need employees from either Finance or IT. OR makes it possible to express these alternative conditions.
To find employees who belong to either Finance or IT, you can combine both department conditions using OR.
SELECT
EmployeeName,
Department
FROM Employees
WHERE Department = 'Finance'
OR Department = 'IT';
OR is useful for category filtering, customer segmentation, department analysis, transaction monitoring, exception reporting, and business-rule analysis.
- OR combines alternative conditions.
- At least one condition must be TRUE.
- OR is commonly used with WHERE.
- OR can be combined with AND.
- Parentheses are useful for complex OR conditions.
What does OR do in SQL?
OR returns a row when at least one of the specified conditions is TRUE.
When would you use OR?
Use OR when a record can satisfy one condition or another condition.