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:
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
Result:
| FirstName | Department | Salary |
|---|---|---|
| Mike | IT | 6000 |
| Tom | IT | 5200 |
Both conditions must be true:
- Department = ‘IT’
- Salary > 5000
Step 3: Using multiple
ANDconditions
You can combine more than two conditions.
Example: IT department, 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
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
Example: IT department OR salary > 5000
Using parentheses is important when combining
ANDandORfor correct logic.
