SQL Keywords

SQL AND

What does the SQL AND operator do?

SQL AND returns TRUE when all combined Boolean expressions evaluate to TRUE, otherwise it returns FALSE or UNKNOWN.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL AND: Supported by PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, Redshift, BigQuery, DB2, and all ANSI-compliant systems.

SQL AND Full Explanation

SQL AND is a logical operator that combines two or more Boolean expressions and yields TRUE only when every operand is TRUE. It is commonly used in WHERE, HAVING, JOIN ON, and CHECK clauses to narrow result sets and enforce data integrity. AND follows three-valued logic: if any operand is FALSE the result is FALSE; if all operands are TRUE the result is TRUE; if no operand is FALSE and at least one is UNKNOWN (NULL comparison) the result is UNKNOWN, which filters out rows in WHERE or HAVING. Operator precedence places NOT first, then AND, then OR, so AND binds more tightly than OR unless parentheses override this order. Most databases allow chaining multiple AND conditions without limits. Indexes can optimize AND filters when columns are indexed independently or with composite indexes, but implicit functions or type mismatches on indexed columns may prevent index use.

SQL AND Syntax

expression1 AND expression2 [AND expression3 ...]

SQL AND Parameters

  • expression1 (BOOLEAN) - First condition to evaluate
  • expression2 (BOOLEAN) - Second condition to evaluate
  • expression3 ... (BOOLEAN) - Optional additional conditions to evaluate

Example Queries Using SQL AND

-- 1. Filter active users who logged in during the last 30 days
SELECT *
FROM users
WHERE active = TRUE
  AND last_login > NOW() - INTERVAL '30 days';

-- 2. Update only paid but unshipped orders
UPDATE orders
SET status = 'shipped'
WHERE paid = TRUE
  AND shipped = FALSE;

-- 3. Group employees hired this year, excluding terminated ones
SELECT department, COUNT(*)
FROM employees
WHERE hire_date >= '2023-01-01'
  AND terminated IS NULL
GROUP BY department;

Expected Output Using SQL AND

  • Returns only users who are marked active and have logged in within 30 days.
  • Changes status to shipped for orders that meet both paid and unshipped conditions.
  • Produces counts by department for employees hired in 2023 who are not terminated.

Use Cases with SQL AND

  • Combine multiple filters in SELECT, UPDATE, DELETE statements.
  • Enforce multi-column constraints inside CHECK definitions.
  • Join tables with compound conditions in ON clauses.
  • Build precise HAVING clauses after GROUP BY.

Common Mistakes with SQL AND

  • Forgetting parentheses when mixing AND and OR, leading to unexpected precedence.
  • Assuming NULL AND TRUE returns FALSE – it actually yields UNKNOWN.
  • Applying functions to indexed columns and losing index benefits.
  • Misreading performance: multiple AND predicates on low-selectivity columns may cause full scans.

Related Topics

OR, NOT, WHERE, HAVING, JOIN ON, XOR, BETWEEN, CASE

First Introduced In

SQL-86 (ANSI X3.135-1986)

Frequently Asked Questions

Does AND have higher precedence than OR in SQL?

Yes. NOT is evaluated first, AND second, OR last. Parentheses let you override this order.

How does NULL affect an AND condition?

If any operand is NULL and none is FALSE, the result is UNKNOWN, which filters out the row in WHERE or HAVING clauses.

Can multiple AND conditions hurt performance?

Too many low-selectivity filters can cause full scans. Proper indexing or composite indexes help.

How can I force a different evaluation order?

Wrap expressions in parentheses to ensure they are evaluated before or after other logical operators.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!