Combining filters

Beginner

The examples in the previous tutorials showed how to use WHERE to filter our data using a single condition.

If you want to use multiple filtering conditions, you can use logical operators AND and OR to combine multiple conditions.

Examples

SELECT *
FROM payroll
WHERE employee_id = 1 AND payment_date > '2024-01-01'

This query will retrieve all columns from the payroll table where both the employee_id column has the value 1 and the payment_date column has a date greater than '2024-01-01'.

SELECT *
FROM payroll
WHERE employee_id = 1 OR employee_id = 2

This query will retrieve all columns from the payroll table where the employee_id column has a value of either 1 or 2 (note: you could also use an IN operator to achieve this).

SELECT *
FROM payroll
WHERE (employee_id = 1 OR employee_id = 2) AND payment_date > '2024-01-01'

This query will retrieve all the columns from the payroll table, but will only return rows where the employee_id is either 1 or 2, and the payment_date is greater than 2024-01-01.

Practice

Now it's your turn! Open the following questions in a new tab to have a go at combining filters in the WHERE clause: