Ira SQL ProIra SQL Pro

Combining WHERE with AND

beginnerfiltering
2 min read

What is AND in a WHERE Clause?

The AND operator combines two or more conditions in a WHERE clause. A row is included in the result only if all conditions evaluate to true.

Syntax

SELECT * FROM table_name
WHERE condition1 AND condition2;
SELECT * FROM table_name
WHERE condition1 AND condition2 AND condition3;

When to Use

  • Filtering by multiple criteria simultaneously
  • Finding rows that meet all business rules
  • Narrowing search results to a specific subset

Key Points

  1. All Must Be True — Every condition joined by AND must be true for the row to appear.
  2. Short-Circuit — PostgreSQL may stop evaluating conditions once one is false.
  3. Parentheses — Use parentheses to clarify complex logic, especially when mixing AND with OR.
  4. NULL Behavior — If any condition involves NULL with =, that condition is unknown (not true), so the row is excluded.
  5. Readability — Break long conditions onto separate lines for readability.

Guided Practice

Solve the challenge below. Use hints when stuck and check your answer for instant feedback.

Practice challengeGuided learning mode

Combining WHERE with AND Challenge

Write a query that find students who are older than 20 AND have grade A.

Expected result

Only students who are both older than 20 and have grade A.

Hidden checks

  • Returned rows and values
  • Output columns and result shape
  • Final database state after the query runs

Lesson guidance

What is AND in a WHERE Clause?

Initializing database...Each run starts from fresh sample data.

More Examples

Three conditions with AND

Find affordable electronics in stock.

Initializing database...Each run starts from fresh sample data.

Frequently Asked Questions

What happens when AND is combined with OR?
AND has higher precedence than OR. Use parentheses to make the intended logic explicit.
Is there a limit to how many AND conditions I can have?
No fixed limit. However, very complex WHERE clauses can be harder to read and may impact query planning.

Related Topics