SQL OR Operator – Filter Any Condition with Examples (2026-27)
The SQL OR operator is used to combine two or more conditions in a WHERE clause. A row is included in the result if AT LEAST ONE condition joined by OR is true. This makes OR more permissive than AND — it widens your filter to include rows matching any of the given conditions. In this beginner-friendly guide you will learn the OR syntax, see four real examples — including OR with three conditions, OR with AND, and a real-world use case — and understand the most common mistakes to avoid.
✅ What is the SQL OR Operator?
✅ The SQL OR operator is a logical operator used inside a WHERE clause to filter rows.
✅ It combines two or more conditions — a row appears in results if ANY ONE condition is true.
✅ Unlike AND, which requires all conditions to be true, OR only requires at least one to be true.
✅ Sample Employees Table:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 90000 | Pune |
| 3 | RAJ | HR | 5000 | Pune |
| 4 | SUJAN | HR | 8000 | Delhi |
| 5 | MEENA | Sales | 12000 | Mumbai |
✅ SQL OR Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition1 OR condition2 OR condition3 ...;
✅ SELECT:- Columns you want to retrieve.
✅ FROM:- The table to query data from.
✅ WHERE:- Starts the filtering section.
✅ OR:- Joins conditions — if ANY ONE is true the row is returned.
✅ Example – IT Department OR HR Department
Retrieve all employees who work in either the IT or HR department.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department = 'IT' OR Department = 'HR';
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 90000 | Pune |
| 3 | RAJ | HR | 5000 | Pune |
| 4 | SUJAN | HR | 8000 | Delhi |
✅ Example – City is Pune OR City is Mumbai
Retrieve all employees located in either Pune or Mumbai.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE City = 'Pune' OR City = 'Mumbai';
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 90000 | Pune |
| 3 | RAJ | HR | 5000 | Pune |
| 5 | MEENA | Sales | 12000 | Mumbai |
SUJAN from Delhi is excluded — Delhi matches neither condition. Everyone else qualifies because their city is either Pune or Mumbai.
✅ Example – Three OR Conditions
You can chain as many OR conditions as you need. Any one condition being true is enough for the row to be included.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE Department = 'IT'
OR Department = 'HR'
OR Department = 'Sales';
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 90000 | Pune |
| 3 | RAJ | HR | 5000 | Pune |
| 4 | SUJAN | HR | 8000 | Delhi |
| 5 | MEENA | Sales | 12000 | Mumbai |
IN as a cleaner alternative:WHERE Department IN ('IT', 'HR', 'Sales') — produces exactly the same result.
✅ Example – OR Combined with AND
You can mix OR and AND in one query. Always use parentheses to group OR conditions — this prevents unexpected logic errors.
✅ SELECT Query:-
SELECT * FROM Employees
WHERE (Department = 'IT' OR Department = 'HR')
AND Salary > 7000;
✅ Result:-
| ID | Name | Department | Salary | City |
|---|---|---|---|---|
| 1 | ANNI | IT | 10000 | Mumbai |
| 2 | POOJA | IT | 90000 | Pune |
| 4 | SUJAN | HR | 8000 | Delhi |
WHERE Department = 'IT' OR Department = 'HR' AND Salary > 7000 — SQL evaluates AND first, which gives: all IT employees (regardless of salary) PLUS HR employees earning more than 7000. That is probably NOT what you want. With parentheses, the OR group is evaluated first, then AND is applied to the whole group.
✅ OR vs AND – Key Differences
| Feature | SQL OR | SQL AND |
|---|---|---|
| Condition requirement | AT LEAST ONE condition must be true | ALL conditions must be true |
| Rows returned | More rows (more permissive) | Fewer rows (more restrictive) |
| Use case | Find IT or HR employees | Find IT employees in Pune |
| All conditions false | Row excluded | Row excluded |
| One condition true | Row included ✅ | Row excluded ❌ |
| All conditions true | Row included ✅ | Row included ✅ |
✅ Key Points to Remember
✅ ANY ONE condition being true is enough — OR is permissive. One true condition includes the row.
✅ Chain as many OR conditions as needed — WHERE A OR B OR C OR D is valid SQL.
✅ Text values need single quotes — WHERE City = 'Pune' not = Pune.
✅ Use parentheses when mixing OR + AND — prevents logic errors.
✅ AND evaluates before OR — without parentheses A OR B AND C means A OR (B AND C).
✅ Consider IN as an alternative — WHERE City IN ('Pune','Mumbai','Delhi') replaces multiple OR conditions on the same column.
✅ OR works with all data types — text, numbers, dates, boolean.
✅ Common SQL OR Mistakes to Avoid
Wrong:
WHERE Department = IT OR City = PuneCorrect:
WHERE Department = 'IT' OR City = 'Pune'Text values must always be wrapped in single quotes.
Wrong:
WHERE Department = 'IT' OR Department = 'HR' AND Salary > 7000Correct:
WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 7000Without parentheses AND is evaluated first, producing unintended results.
Wrong:
WHERE Department = 'IT' OR 'HR'Correct:
WHERE Department = 'IT' OR Department = 'HR'Each OR condition needs the full column name, operator, and value.
If you want employees in IT who are also in Pune, do not use OR:
Wrong:
WHERE Department = 'IT' OR City = 'Pune' — returns all IT employees AND all Pune employees separately.Correct:
WHERE Department = 'IT' AND City = 'Pune' — returns only IT employees in Pune.
Verbose:
WHERE City = 'Pune' OR City = 'Mumbai' OR City = 'Delhi'Cleaner:
WHERE City IN ('Pune', 'Mumbai', 'Delhi')Both work the same way, but IN is easier to read and maintain for long lists.
✅ Frequently Asked Questions (FAQ)
WHERE Department = 'IT' OR Department = 'HR' OR Department = 'Sales'. Any one condition being true is enough for the row to be returned.WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 9000. Without parentheses, AND is evaluated before OR, which can produce unexpected results.WHERE Department = 'IT' OR City = 'Pune'.