SQL OR Operator Tutorial
Example Table
We will use the following table named employees
for our examples:
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
employee_name VARCHAR(50),
department VARCHAR(50),
salary DECIMAL(10, 2)
);
INSERT INTO employees (employee_id, employee_name, department, salary) VALUES
(1, 'Alice Johnson', 'HR', 60000.00),
(2, 'Bob Smith', 'IT', 75000.00),
(3, 'Charlie Brown', 'Finance', 50000.00),
(4, 'Diana Prince', 'IT', 80000.00),
(5, 'Eve Davis', 'Marketing', 55000.00);
Employees Table
employee_id | employee_name | department | salary |
---|---|---|---|
1 | Alice Johnson | HR | 60000.00 |
2 | Bob Smith | IT | 75000.00 |
3 | Charlie Brown | Finance | 50000.00 |
4 | Diana Prince | IT | 80000.00 |
5 | Eve Davis | Marketing | 55000.00 |
Using the SQL OR Operator
The SQL OR operator is used to combine multiple conditions in a SQL query. The query returns rows that satisfy at least one of the conditions.
Example: Using the OR Operator
To find employees who are either in the IT department or have a salary greater than 60000, use the following query:
SELECT employee_name, department, salary
FROM employees
WHERE department = 'IT' OR salary > 60000;
Result:
employee_name | Bob Smith |
---|---|
department | IT |
salary | 75000.00 |
employee_name | Diana Prince |
department | IT |
salary | 80000.00 |
employee_name | Alice Johnson |
department | HR |
salary | 60000.00 |