Or in SQL
OR Operator in SQL
The OR operator is a logical operator used to combine multiple conditions in a WHERE clause. The result is TRUE if any of the combined conditions is TRUE.
? Syntax:
SELECT column1, column2, ...FROM table_nameWHERE condition1 OR condition2 OR condition3 ...;? Example:
Get employees who are either in department 10 or have a salary greater than 50,000:
SELECT employee_name, department_id, salaryFROM employeesWHERE department_id = 10 OR salary > 50000;Truth Table for OR:
| Condition 1 | Condition 2 | Result (Condition1 OR Condition2) |
|---|---|---|
| TRUE | TRUE | TRUE |
| TRUE | FALSE | TRUE |
| FALSE | TRUE | TRUE |
| FALSE | FALSE | FALSE |
Usage Notes:
Can combine any number of conditions.
Often combined with
ANDand parentheses for complex logic, e.g.:
WHERE (department_id = 10 OR department_id = 20) AND salary > 40000If you want, I can show you examples combining OR with other operators!