SQL Tutorial

SQL OR Operator – Filter Records with Multiple Conditions (2026-27)

The SQL OR operator is used to filter records where at least one of the specified conditions is true. Unlike AND which requires every condition to be true, OR is more permissive — a row is returned if any one condition passes. This makes OR ideal when you want to retrieve records from multiple categories, names, or value ranges at once. In this beginner-friendly guide you will learn the OR syntax, see four real working examples — OR with departments, salary, names, and combined with AND — plus 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.

✅ A row is returned if at least one condition is true — even if the others are false.

✅ OR is more permissive than AND and typically returns more rows.

💡 Real-world example: You want employees from either the IT department OR the Sales department. Using OR means an employee in IT appears, and an employee in Sales also appears — you don't need to be in both.

Sample Employees Table:-

Employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJSales5000Pune
4SUJANHR8000Delhi
5MEENAHR12000Mumbai

✅ 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 — at least one must be true for the row to be returned.

ℹ️ Key rule: If ANY ONE condition in an OR chain evaluates to TRUE, the row appears in results. Only when ALL conditions are false is the row excluded.

✅ Example 1 – Department is IT OR Sales

SELECT Query:-

SELECT * FROM Employees
WHERE Department = 'IT' OR Department = 'Sales';

Result:-

Result — IT and Sales employees
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT90000Pune
3RAJSales5000Pune
💡 Note: SUJAN and MEENA are in HR — neither condition matches them, so they are excluded. All IT and Sales employees pass at least one condition.

✅ Example 2 – Salary > 10000 OR Department is Sales

SELECT Query:-

SELECT * FROM Employees
WHERE Salary > 10000 OR Department = 'Sales';

Result:-

Result — Salary > 10000 or in Sales department
IDNameDepartmentSalaryCity
2POOJAIT90000Pune
3RAJSales5000Pune
5MEENAHR12000Mumbai
ℹ️ Explanation: POOJA passes because her salary is 90000 (> 10000). RAJ passes because he is in Sales. MEENA passes because her salary is 12000 (> 10000). ANNI earns exactly 10000 (not > 10000) and is not in Sales — excluded.

✅ Example 3 – Name is ANNI OR RAJ

SELECT Query:-

SELECT * FROM Employees
WHERE Name = 'ANNI' OR Name = 'RAJ';

Result:-

Result — Employees named ANNI or RAJ
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
3RAJSales5000Pune
💡 Tip: When checking the same column for many values, consider using IN instead: WHERE Name IN ('ANNI', 'RAJ') is cleaner and gives the same result.

✅ Example 4 – OR Combined with AND

You can mix OR and AND in one query. Always use parentheses to group OR conditions correctly.

SELECT Query:-

SELECT * FROM Employees
WHERE City = 'Pune'
  AND (Department = 'IT' OR Department = 'Sales');

Result:-

Result — Pune employees in IT or Sales
IDNameDepartmentSalaryCity
2POOJAIT90000Pune
3RAJSales5000Pune
⚠️ Always use parentheses with AND + OR! Without brackets, WHERE City = 'Pune' AND Department = 'IT' OR Department = 'Sales' means (City = 'Pune' AND Department = 'IT') OR Department = 'Sales' — which returns ALL Sales employees regardless of city. Parentheses prevent this.

✅ OR vs AND – Key Differences

FeatureSQL ORSQL AND
Condition requirementAT LEAST ONE must be trueALL conditions must be true
Rows returnedMore rows (permissive)Fewer rows (restrictive)
One false conditionRow still returned if another is trueRow excluded
Use caseIT or Sales employeesIT employees in Pune
Best withSame column, multiple valuesDifferent columns, all required

✅ OR vs IN – When to Use Each

When you are checking the same column against multiple values, IN is a cleaner alternative to multiple OR conditions.

FeatureORIN
Same result?YesYes
ReadabilityGets messy with 4+ valuesClean with any number of values
PerformanceSimilarOften faster with indexes
ExampleDept='IT' OR Dept='HR' OR Dept='Sales'Dept IN ('IT','HR','Sales')
💡 Rule of thumb: Use OR when mixing different columns (Salary > 50000 OR City = 'Pune'). Use IN when checking one column against many values (Department IN ('IT','HR','Sales')).

✅ Key Points to Remember

✅ At least ONE condition must be true — OR is permissive, AND is restrictive.

✅ Chain as many OR conditions as needed — no limit on how many you use.

✅ Always use parentheses when mixing AND and OR — prevents logic errors.

✅ AND is evaluated before OR — without parentheses A AND B OR C means (A AND B) OR C.

✅ Use IN for cleaner code — when checking the same column against multiple values.

✅ Text values need single quotesWHERE Department = 'IT' not = IT.


✅ Common SQL OR Mistakes to Avoid

❌ Mistake 1: Missing parentheses when mixing AND and OR
Wrong: WHERE City = 'Pune' AND Department = 'IT' OR Department = 'Sales'
Correct: WHERE City = 'Pune' AND (Department = 'IT' OR Department = 'Sales')
Without parentheses the query returns all Sales employees regardless of city.
❌ Mistake 2: Repeating the column name incorrectly
Wrong: WHERE Department = 'IT' OR 'Sales'
Correct: WHERE Department = 'IT' OR Department = 'Sales'
Each OR condition must include the full column name, operator, and value.
❌ Mistake 3: Using OR when AND is needed
If you need employees who are in IT AND earn over 50000, using OR gives all IT employees plus all high earners — not what you want. Think clearly about whether you need any condition or all conditions.
❌ Mistake 4: Using many OR conditions on one column
Wrong: WHERE Dept='IT' OR Dept='HR' OR Dept='Sales' OR Dept='Finance'
Correct: WHERE Dept IN ('IT','HR','Sales','Finance')
Use IN for cleaner, more readable, and often faster queries.

✅ Frequently Asked Questions (FAQ)

What does the SQL OR operator do?
The SQL OR operator returns a row if at least ONE of the conditions joined by OR is true. Unlike AND which requires all conditions to be true, OR is more permissive and typically returns more rows.
What is the difference between SQL OR and AND?
OR returns a row if ANY one condition is true — more rows returned. AND returns a row only if ALL conditions are true — fewer rows. OR is permissive; AND is restrictive.
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 true condition includes the row in results.
Can I combine OR and AND in the same SQL query?
Yes. Always use parentheses to group OR conditions: WHERE City = 'Pune' AND (Department = 'IT' OR Department = 'HR'). Without parentheses AND is evaluated before OR, which can give unexpected results.
Is there a better alternative to multiple OR conditions?
Yes. When checking the same column against many values, use IN instead: WHERE Department IN ('IT', 'HR', 'Sales') is cleaner and faster than three OR conditions on the same column.
Does OR work with numbers and dates in SQL?
Yes. OR works with any data type — text (VARCHAR), numbers (INT, DECIMAL), and dates (DATE). Example: WHERE Salary > 50000 OR JoinDate > '2024-01-01'

✍️ 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.