The AND operator is used in a WHERE clause to combine two or more conditions.

  • All conditions must be true for a row to be included in the result set.
  • If any condition is false, the row is excluded.

Basic syntax:

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

Step 1: Example table

Assume the Employees table:

EmployeeID FirstName LastName Department Salary
1 John Doe IT 5000
2 Jane Smith HR 4500
3 Mike Brown IT 6000
4 Sara White HR 4700
5 Tom Green IT 5200

Step 2: Using AND to filter rows

Example: IT department with salary greater than 5000

SELECT FirstName, Department, Salary
FROM Employees
WHERE Department = 'IT' AND Salary > 5000;

Result:

FirstName Department Salary
Mike IT 6000
Tom IT 5200

Both conditions must be true:

  1. Department = ‘IT’
  2. Salary > 5000

Step 3: Using multiple AND conditions

You can combine more than two conditions.

Example: IT department, salary > 5000, and EmployeeID > 3

SELECT FirstName, Department, Salary
FROM Employees
WHERE Department = 'IT' AND Salary > 5000 AND EmployeeID > 3;

Result:

FirstName Department Salary
Tom IT 5200

Step 4: AND with other operators

AND works with any comparison operator:

  • = Equal
  • <> Not equal
  • < Less than
  • > Greater than
  • <= Less than or equal
  • >= Greater than or equal

Example: HR department with salary between 4500 and 4800

SELECT FirstName, Department, Salary
FROM Employees
WHERE Department = 'HR' AND Salary >= 4500 AND Salary <= 4800;

Result:

FirstName Department Salary
Jane HR 4500
Sara HR 4700

Step 5: AND vs OR

  • AND → all conditions must be true
  • OR → any condition can be true

Example: IT department AND salary > 5000

-- Only IT employees with salary > 5000
WHERE Department = 'IT' AND Salary > 5000

Example: IT department OR salary > 5000

-- All IT employees + anyone with salary > 5000
WHERE Department = 'IT' OR Salary > 5000

Using parentheses is important when combining AND and OR for correct logic.

Categorized in:

SQL Server,