Predicate in SQL: Definition, Types and Examples

· 8 MIN

TL;DR: A predicate in SQL is a condition that evaluates to TRUE, FALSE or UNKNOWN, such as amount > 100 or email IS NULL. WHERE, ON and HAVING keep only the rows where the predicate is TRUE, so a NULL anywhere can silently drop rows. AI for Database writes these predicates for you from a plain-English question and shows the SQL with every answer, so you can check exactly which filter ran.

Want to skip writing filters by hand? Try AI for Database free at aifordatabase.com (start here, sample data included).

A predicate in SQL is an expression that returns a truth value (TRUE, FALSE or UNKNOWN) for each row, and the clause it sits in keeps only the rows where it is TRUE. In SELECT * FROM orders WHERE subtotal > 35, the predicate is subtotal > 35 (Metabase glossary). Predicates appear in WHERE (filter rows), ON (match rows in a join), HAVING (filter groups) and CASE WHEN. The main SQL predicate types are comparison (=, <>, <, >), BETWEEN, IN, LIKE, EXISTS, IS NULL and IS DISTINCT FROM, plus ANY/ALL quantified comparisons (Microsoft Learn, Actian docs).

How AI for Database handles predicates for you

Most people who search for SQL predicates are trying to filter data correctly. AI for Database does that step from a question:

What it does not do: it does not tune your indexes. If a predicate is slow (see sargability below), that is still a database job.

A plain-English question becomes SQL predicates that filter rows before the answer is returned
FIG 01 — The generated SQL is shown with every answer.

What is a predicate in SQL, exactly?

A predicate is any boolean-valued condition. The SQL standard and every major engine use three-valued logic: a predicate can be TRUE, FALSE or UNKNOWN (SAP MaxDB reference). UNKNOWN appears when NULL is involved. A clause keeps a row only on TRUE; FALSE and UNKNOWN are both discarded. Predicates combine with AND, OR and NOT into a "search condition".

Why it matters: a support lead asks for "all tickets not assigned to Priya". The query WHERE assignee <> 'Priya' looks right, but every unassigned ticket (assignee NULL) disappears, because NULL <> 'Priya' is UNKNOWN, not TRUE. The backlog report undercounts exactly the tickets that need attention.

What are the types of SQL predicates?

PredicateExampleTRUE whenNULL behavior
Comparisonamount > 100the comparison holdsUNKNOWN if either side is NULL
BETWEENamount BETWEEN 50 AND 10050 <= amount <= 100 (inclusive)UNKNOWN if any value is NULL
INstatus IN ('paid','refunded')value equals one list itemNOT IN with a NULL in the list is never TRUE
LIKEemail LIKE '%@gmail.com'string matches patternUNKNOWN on NULL
IS NULLcoupon_code IS NULLvalue is NULLnever UNKNOWN
IS DISTINCT FROMa IS DISTINCT FROM bvalues differ, NULL-awarenever UNKNOWN
EXISTSEXISTS (SELECT 1 FROM ...)subquery returns a rownever UNKNOWN
ANY / ALLamount > ALL (SELECT ...)holds for any / all rowscan be UNKNOWN

Comparison predicates

=, <> (or !=), <, >, <=, >=. In PostgreSQL, "ordinary comparison operators yield null (signifying 'unknown'), not true or false, when either input is null. For example, 7 = NULL yields null, as does 7 <> NULL" (PostgreSQL docs).

BETWEEN

a BETWEEN x AND y is equivalent to a >= x AND a <= y, so both ends are included. PostgreSQL adds BETWEEN SYMMETRIC, which swaps the bounds if they are reversed: 2 BETWEEN SYMMETRIC 3 AND 1 is true (PostgreSQL docs). For timestamps, inclusive upper bounds cause off-by-one-day bugs; our guide to Postgres date BETWEEN covers the safe >= start AND < next_day pattern.

IN and ANY

status IN ('paid','refunded') is shorthand for status = 'paid' OR status = 'refunded'. PostgreSQL also accepts arrays with = ANY(array), explained in PostgreSQL ANY with arrays.

LIKE

In LIKE patterns, % matches any sequence of zero or more characters and _ matches exactly one (PostgreSQL pattern matching). For substring checks across engines see SQL CONTAINS.

IS NULL and IS DISTINCT FROM

IS NULL is the only correct way to test for NULL. PostgreSQL's docs say plainly: "Do not write expression = NULL" (source). IS DISTINCT FROM behaves like <> for non-null values, returns false when both sides are NULL and true when only one is.

EXISTS

EXISTS is TRUE when its subquery returns at least one row. The columns it selects do not matter; EXISTS (SELECT 1 ...) and EXISTS (SELECT * ...) are equivalent in PostgreSQL, which skips evaluating the output list (PostgreSQL subquery expressions).

-- customers who placed at least one order in October
SELECT c.id, c.name
FROM customers c
WHERE EXISTS (
  SELECT 1 FROM orders o
  WHERE o.customer_id = c.id
    AND o.created_at >= '2026-10-01'
    AND o.created_at <  '2026-11-01'
);

Why does a predicate with NULL return no rows?

Because a NULL comparison is UNKNOWN and WHERE keeps only TRUE. Here is a worked example with five tickets:

-- tickets: (1,'Priya'), (2,'Sam'), (3,NULL), (4,'Priya'), (5,NULL)
SELECT id FROM tickets WHERE assignee <> 'Priya';
-- returns 1 row: id 2
SELECT id FROM tickets WHERE assignee IS DISTINCT FROM 'Priya';
-- returns 3 rows: ids 2, 3, 5

The first query reports 1 ticket not owned by Priya; the true answer is 3. Two of five rows (40%) vanished.

The <> predicate is UNKNOWN for NULL assignees, so tickets 3 and 5 are dropped
FIG 02 — Only TRUE rows survive: 1 row instead of 3.

The worst version is NOT IN with a subquery. If the subquery returns even one NULL and the value has no match, NOT IN yields null, not true (PostgreSQL docs), so the query returns zero rows:

-- returns nothing if any blocked_users.user_id is NULL
SELECT id FROM users
WHERE id NOT IN (SELECT user_id FROM blocked_users);

-- safe version
SELECT u.id FROM users u
WHERE NOT EXISTS (SELECT 1 FROM blocked_users b WHERE b.user_id = u.id);

What is a sargable predicate?

A sargable predicate (from "Search ARGument ABLE") is one the database can answer with an index seek, because the indexed column stands alone on one side of the operator. Wrapping the column in a function or arithmetic usually makes it non-sargable, forcing the engine to evaluate every row.

Non-sargableSargable rewrite
WHERE date(created_at) = '2026-11-01'WHERE created_at >= '2026-11-01' AND created_at < '2026-11-02'
WHERE amount * 1.18 > 118WHERE amount > 100
WHERE email LIKE '%@acme.com'store the domain in its own indexed column
WHERE lower(email) = 'ana@acme.com'add an expression index on lower(email)

PostgreSQL supports indexes on expressions, so CREATE INDEX ON users (lower(email)); makes the last predicate index-friendly (PostgreSQL docs). A leading % in LIKE prevents a normal B-tree index range scan. To confirm what the planner does, run EXPLAIN ANALYZE and compare "Seq Scan" with "Index Scan"; our PostgreSQL EXPLAIN guide walks through the output.

EXPLAIN ANALYZE
SELECT id FROM orders
WHERE created_at >= '2026-11-01' AND created_at < '2026-11-02';
-- with an index on created_at, expect: Index Scan using orders_created_at_idx

Predicate vs condition vs expression: what is the difference?

TermMeaningExample
Expressionanything that produces a valueamount * 1.18
Predicatean expression that produces TRUE, FALSE or UNKNOWNamount > 100
Search conditionone or more predicates joined by AND, OR, NOTamount > 100 AND status = 'paid'

People often use "condition" and "predicate" interchangeably; the precise distinction is that a search condition can contain several predicates. The WHERE vs HAVING split is about timing: WHERE predicates filter rows before GROUP BY, HAVING predicates filter groups after it.

Pitfalls to check before you trust a filter

For more syntax at a glance, keep the SQL cheat sheet open.

Frequently Asked Questions

What is a predicate in SQL?

A predicate is a condition that evaluates to TRUE, FALSE or UNKNOWN for each row, such as price > 10. WHERE, ON and HAVING keep only the rows where it is TRUE.

What are the types of SQL predicates?

Comparison, BETWEEN, IN, LIKE, IS NULL, IS DISTINCT FROM, EXISTS and quantified ANY/ALL. SQL Server also has full-text predicates CONTAINS and FREETEXT ([Microsoft Learn](https://learn.microsoft.com/en-us/sql/t-sql/queries/predicates)).

Why does a predicate with NULL return no rows?

Any ordinary comparison with NULL returns UNKNOWN, and filters discard UNKNOWN just like FALSE. Use IS NULL, IS DISTINCT FROM or NOT EXISTS instead.

What is a sargable predicate?

One the optimizer can satisfy with an index seek because the indexed column is not wrapped in a function or calculation. created_at >= '2026-11-01' is sargable; date(created_at) = '2026-11-01' usually is not.

Is a JOIN condition a predicate?

Yes. The ON clause of a join is a predicate that decides which pairs of rows match.

Can I filter data without writing predicates myself?

Yes. AI for Database turns a question into SQL with the right predicates, runs it read-only and shows the SQL so you can check it. Try AI for Database free at aifordatabase.com ([sign up](https://app.aifordatabase.com/signup), sample data included).

Ready to try AI for Database?

Query your database in plain English. No SQL required. Start free today.