AND: Combine Multiple Conditions

The AND keyword lets you combine several conditions in a WHERE clause. All the conditions must be true for a row to be in the result.

Syntax

SELECT column1, column2 FROM table_name
WHERE condition1 AND condition2 AND ...;

Example 1: Employees in IT and older than 30

SELECT name, age, department FROM employees
WHERE department = 'IT' AND age > 30;

Output:

  name  | age | department 
--------+-----+------------
 Bob    |  32 | IT
 Thomas |  33 | IT
(2 rows)

This returns only the employees who are both in IT and older than 30.

Example 2: Female employees in Sales

SELECT name, gender, department FROM employees
WHERE department = 'Sales' AND gender = 'female';

Output:

 name | gender | department 
------+--------+------------
 Lucy | female | Sales
 Tina | female | Sales
(2 rows)

This filters employees by two rules at the same time.


Use AND when all conditions must be true. If even one condition is false, the row is not in the result.

In the exercise, combine three conditions with AND.