SQL Tutorial

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.

💡 Real-world example: You want to find employees who work in the IT department OR the HR department. Using OR means either condition is enough — an employee in IT appears, an employee in HR also appears, even if they don't satisfy both conditions at once.

Sample Employees Table:-

Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJHR5000Pune
4SUJANHR8000Delhi
5MEENASales12000Mumbai

✅ 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.

ℹ️ Key rule: Only ONE condition needs to be TRUE for the row to appear. Even if all other conditions are false, one true condition is enough.

✅ 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:-

Result — IT or HR employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJHR5000Pune
4SUJANHR8000Delhi
💡 Notice: MEENA from Sales is not returned because neither condition matches her department. All IT and HR employees are returned because at least one condition is true for each of them.

✅ 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:-

Result — Employees in Pune or Mumbai
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJHR5000Pune
5MEENASales12000Mumbai

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:-

Result — IT, HR, or Sales employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJHR5000Pune
4SUJANHR8000Delhi
5MEENASales12000Mumbai
ℹ️ Tip: When filtering on multiple values of the same column, consider using 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:-

Result — IT or HR employees earning more than 7000
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
4SUJANHR8000Delhi
⚠️ Always use parentheses with OR + AND! Without brackets: 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

FeatureSQL ORSQL AND
Condition requirementAT LEAST ONE condition must be trueALL conditions must be true
Rows returnedMore rows (more permissive)Fewer rows (more restrictive)
Use caseFind IT or HR employeesFind IT employees in Pune
All conditions falseRow excludedRow excluded
One condition trueRow included ✅Row excluded ❌
All conditions trueRow 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 neededWHERE A OR B OR C OR D is valid SQL.

✅ Text values need single quotesWHERE 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 alternativeWHERE 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

❌ Mistake 1: Missing single quotes around text values
Wrong: WHERE Department = IT OR City = Pune
Correct: WHERE Department = 'IT' OR City = 'Pune'
Text values must always be wrapped in single quotes.
❌ Mistake 2: Mixing OR and AND without parentheses
Wrong: WHERE Department = 'IT' OR Department = 'HR' AND Salary > 7000
Correct: WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 7000
Without parentheses AND is evaluated first, producing unintended results.
❌ Mistake 3: Repeating the column name incorrectly
Wrong: WHERE Department = 'IT' OR 'HR'
Correct: WHERE Department = 'IT' OR Department = 'HR'
Each OR condition needs the full column name, operator, and value.
❌ Mistake 4: Using OR when AND is needed
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.
❌ Mistake 5: Not using IN for multiple values on the same column
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)

What does the SQL OR operator do?
The SQL OR operator combines 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. It is more permissive than AND and returns more rows.
What is the difference between SQL OR and AND?
OR requires at least ONE condition to be true for a row to be returned. AND requires ALL conditions to be true. OR is more permissive and returns more rows; AND is more restrictive and returns fewer rows.
Can I use more than two conditions with OR?
Yes. You can chain as many OR conditions as needed: WHERE Department = 'IT' OR Department = 'HR' OR Department = 'Sales'. Any one condition being true is enough for the row to be returned.
Can I combine OR and AND in the same query?
Yes. Use parentheses to control precedence: WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 9000. Without parentheses, AND is evaluated before OR, which can produce unexpected results.
Does SQL OR work with text and number columns?
Yes. OR works with any data type — text (VARCHAR), numbers (INT, DECIMAL), dates (DATE), and boolean values. Always wrap text values in single quotes: WHERE Department = 'IT' OR City = 'Pune'.
What happens if all OR conditions are false?
If every condition in an OR chain is false, the row is excluded from the result. At least one condition must evaluate to TRUE for the row to appear in the result set.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.