You can combine multiple conditions in a WHERE clause using logical operators such as AND, OR, and NOT. Here’s how each operator works:
- AND: Both conditions must be true.
- OR: At least one of the conditions must be true.
- NOT: Negates a condition.
Example:
SELECT * FROM employees
WHERE department = 'Sales' AND salary > 50000;
This query retrieves employees who are in the 'Sales' department and have a salary greater than 50,000.
Using OR:
SELECT * FROM employees
WHERE department = 'Sales' OR department = 'Marketing';
This query retrieves employees who are either in the 'Sales' or 'Marketing' department.
Using NOT:
SELECT * FROM employees
WHERE NOT department = 'HR';
This query retrieves employees who are not in the 'HR' department.
Combining Conditions:
You can also combine these operators:
SELECT * FROM employees
WHERE (department = 'Sales' OR department = 'Marketing') AND salary > 50000;
This query retrieves employees who are either in 'Sales' or 'Marketing' and have a salary greater than 50,000.
