DevLearningTools

LEARN · SQL

SQL AND

AND combines multiple WHERE conditions so that every one of them must be true for a row to match. Learn the syntax and chaining more than two conditions.

A single WHERE condition narrows a query to one test, department = 'Engineering'. AND combines two or more tests into one, matching only rows where every single condition is true.

Learning Objectives

  • Combine two or more conditions with AND.
  • Understand that every AND condition must be true for a row to match.
  • Chain more than two conditions with AND.

Condition A

department = 'Engineering'

AND Condition B

salary > 95000

Matching Rows

Only rows where both are true

AND: Every Condition Must Be True

Both conditions have to be true for a row to be returned. An employee in Engineering earning 90000 doesn't match, department is right but salary isn't.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT first_name, department, salary
FROM employees
WHERE department = 'Engineering' AND salary > 95000;

Chaining More Than Two Conditions

Any number of conditions can be chained with AND, every single one has to be true. AND is standard SQL, identical across every database in this course.

MySQL / MariaDB / PostgreSQL / SQLite / SQL Server / Oracle
SELECT first_name, department, salary
FROM employees
WHERE department = 'Engineering' AND salary > 90000 AND status = 'active';

Try It Yourself

Write a query returning active employees in Engineering earning over 90000.

Answer
SELECT first_name, salary
FROM employees
WHERE department = 'Engineering' AND salary > 90000 AND status = 'active';

Frequently Asked Questions

Is there a limit to how many conditions I can chain with AND?

No practical limit from SQL itself. Readability becomes the real constraint, past four or five chained conditions, it's often worth splitting the logic into a view or breaking it across multiple lines for clarity.

Does the order of AND conditions affect the result?

No, A AND B AND C returns exactly the same rows regardless of the order they're written in. A query optimizer may evaluate them in a different order internally for performance, but the logical result is unaffected by how you write it.

Common Beginner Mistakes

Expecting AND to work like a natural-language "and" (combining results, like a union of two lists)

In everyday speech, "people in Engineering and Research" often means both groups combined. In SQL, WHERE department = 'Engineering' AND department = 'Research' matches nobody, no single row can have both values at once. That combined-list meaning is what OR expresses, not AND.

Repeating the column name unnecessarily when checking a range

WHERE salary > 85000 AND salary < 95000 works, but BETWEEN, covered in a later lesson, expresses the same inclusive-range idea more directly.

Best Practices

  • Use AND when a row must satisfy every condition at once, not when you mean "any of these groups."
  • Break a long chain of AND conditions across multiple lines for readability.
  • Reach for BETWEEN instead of two AND'd range comparisons on the same column.

Interview Questions

Why does WHERE department = 'Engineering' AND department = 'Research' always return zero rows?

A single row's department column holds exactly one value, it can't simultaneously equal 'Engineering' and 'Research'. This is a common mix-up with the everyday meaning of "and," the correct operator for "either of these" is OR, not AND.

Write a query for employees who are active, in Engineering, and earn more than 100000.

SELECT first_name FROM employees WHERE status = 'active' AND department = 'Engineering' AND salary > 100000; — three chained AND conditions, all three must be true for a row to match.

Summary

This lesson covered combining WHERE conditions with AND, where every single condition must be true for a row to match, and chaining more than two conditions together.

What's Next?

The next lesson covers OR, matching a row when at least one condition is true, and what happens once AND and OR are mixed in the same query.

</>

Ready to Practice SQL?

Write and run real SQL queries online, right in your browser, no install or signup required. Pick a playground based on which database you want to practice on.

SQLite / PostgreSQL

Fast, no server, no ads.

Open DB Fiddle ↗

MySQL / SQL Server

Switch databases with one dropdown.

Open SQL Fiddle ↗

Both open a third-party SQL playground in a new tab. External site terms and privacy policy apply.