Logical operators help you combine multiple conditions in the WHERE clause.
| Operator | Description | Example |
|---|---|---|
AND |
Both conditions must be true | salary > 50000 AND department = 'Engineering' |
OR |
At least one condition is true | department = 'HR' OR department = 'Finance' |
NOT |
Negates a condition | NOT department = 'Marketing' |
Both conditions must be satisfied for the row to be selected.
-- Employees in Engineering with salary > 70000
SELECT emp_name, department, salary
FROM employees
WHERE department = 'Engineering' AND salary > 70000;
Explanation:
department = 'Engineering' AND salary > 70000 will be returned.Either condition can be true.
-- Employees in HR or Finance
SELECT emp_name, department
FROM employees
WHERE department = 'HR' OR department = 'Finance';
Explanation:
Negates a condition.
-- Employees NOT in Engineering
SELECT emp_name, department
FROM employees
WHERE NOT department = 'Engineering';
Explanation: