OR Operator - SQL
Overview
The OR Operator in SQL is used to combine multiple conditions in a WHERE clause. It returns true if at least one of the specified conditions is true.
Syntax:
SELECT column
FROM table_name
WHERE condition1 OR condition2
condition1 OR condition2
checks if either condition1
or condition2
is true.
Sample Data:
first_name | salary |
---|---|
Frank | 123000 |
Jane | 135000 |
Ashley | 140000 |
Glenn | 115000 |
Kelly | 125000 |
Richard | 120000 |
George | 105000 |
Kyle | 200000 |
James | 107000 |
Gustavo | 100000 |
Example
In this example, we are returning the first_name and the salary column. We then use the OR operator to filter for multiple conditions and return a row that meets at least one of the conditions. The first condition being a salary over 125000 and the second condition being that the first_name starts with the letter G.
Example:
SELECT first_name, salary
FROM company.employees
WHERE salary > 125000 OR first_name LIKE 'G%'