OR — Match Either Condition

The OR keyword in SQL allows you to combine multiple conditions in a WHERE clause where any one of them can be true.

If at least one condition is true, the row will be included in the result.


Syntax

SELECT column1, column2, ... FROM table_name
WHERE condition1 OR condition2 OR ...;

Example 1: Employees in HR or Finance

SELECT name, department FROM employees
WHERE department = 'HR' OR department = 'Finance';

Example 2: Employees in HR or age under 26

SELECT name, age, department FROM employees
WHERE department = 'HR' OR age < 26;

This returns employees who are either in the HR department or are younger than 26.


This fetches employees from either department.


Combining AND and OR

You can combine AND and OR to create more complex filters. Use parentheses () to group conditions and control the logic.

Example: Employees in HR or Finance and Female

SELECT name, department, gender FROM employees
WHERE (department = 'HR' OR department = 'Finance') AND gender = 'female';

This returns employees who are female and work in either the HR or Finance department.


Tip

Use OR when you want to match at least one of the conditions.


Using OR helps you broaden your query results and explore data that fits any of your specified criteria.