---
title: "Predicate in SQL: Definition, Types and Examples"
description: "A predicate in SQL is a condition that evaluates to TRUE, FALSE or UNKNOWN, such as amount > 100 or email IS NULL."
canonical: "https://www.aifordatabase.com/blog/predicate-in-sql/"
author: "Dhrumil Barot"
author_bio: "Dhrumil is an enterprise analytics expert. Dhrumil built AI for Database so anyone on a team can get answers from live company data in plain English, without waiting on a data team."
published: 2026-11-25
updated: 2026-11-25
---

# Predicate in SQL: Definition, Types and Examples

**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](https://app.aifordatabase.com/signup), 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](https://www.metabase.com/glossary/predicate)). 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](https://learn.microsoft.com/en-us/sql/t-sql/queries/predicates), [Actian docs](https://docs.actian.com/actiandataplatform/SQLLanguage/Predicates_in_SQL.html)).

## 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:

*   **Natural language queries.** Ask "Show me orders over $100 from last month that have no coupon" and the AI translates it into SQL with the predicates (`amount > 100`, a date range, `coupon_code IS NULL`), runs it and returns a table or chart.
*   **The SQL is shown with every answer**, so you can read each predicate and catch a wrong filter. Answers are read-only.
*   **Self-refreshing dashboards** keep the filtered result current on a schedule, and **action workflows** fire a Slack alert, email or webhook when a condition like "daily signups drop below 50" becomes true.
*   **Sources:** PostgreSQL, MySQL, SQL Server, Oracle, SQLite, MongoDB, Supabase, BigQuery and more.
*   **Price:** start free on sample data; Pro is $20 per user per month (paid as $20 of non-expiring credits) and Team is $50 per user per month ([pricing](https://www.aifordatabase.com/pricing/), read 2026-11-25).

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](https://cdn.sanity.io/images/upsr56wu/production/e92782b74d8e83e885a85ab5210bccb77da60db8-1344x326.png?w=1280)

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](https://maxdb.sap.com/doc/7_7/45/5107ae6a4f3bdbe10000000a1553f7/content.htm)). 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?

| Predicate | Example | TRUE when | NULL behavior |
| --- | --- | --- | --- |
| Comparison | `amount > 100` | the comparison holds | UNKNOWN if either side is NULL |
| BETWEEN | `amount BETWEEN 50 AND 100` | 50 <= amount <= 100 (inclusive) | UNKNOWN if any value is NULL |
| IN | `status IN ('paid','refunded')` | value equals one list item | NOT IN with a NULL in the list is never TRUE |
| LIKE | `email LIKE '%@gmail.com'` | string matches pattern | UNKNOWN on NULL |
| IS NULL | `coupon_code IS NULL` | value is NULL | never UNKNOWN |
| IS DISTINCT FROM | `a IS DISTINCT FROM b` | values differ, NULL-aware | never UNKNOWN |
| EXISTS | `EXISTS (SELECT 1 FROM ...)` | subquery returns a row | never UNKNOWN |
| ANY / ALL | `amount > ALL (SELECT ...)` | holds for any / all rows | can 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](https://www.postgresql.org/docs/current/functions-comparison.html)).

### 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](https://www.postgresql.org/docs/current/functions-comparison.html)). For timestamps, inclusive upper bounds cause off-by-one-day bugs; our guide to [Postgres date BETWEEN](https://www.aifordatabase.com/blog/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](https://www.aifordatabase.com/blog/postgresql-any-array/).

### LIKE

In LIKE patterns, `%` matches any sequence of zero or more characters and `_` matches exactly one ([PostgreSQL pattern matching](https://www.postgresql.org/docs/current/functions-matching.html)). For substring checks across engines see [SQL CONTAINS](https://www.aifordatabase.com/blog/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](https://www.postgresql.org/docs/current/functions-comparison.html)). `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](https://www.postgresql.org/docs/current/functions-subquery.html)).

```
-- 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](https://cdn.sanity.io/images/upsr56wu/production/0199722123129048b4d1bcd3af1fdf2b69d2a343-1344x502.png?w=1280)

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](https://www.postgresql.org/docs/current/functions-subquery.html)), 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-sargable | Sargable rewrite |
| --- | --- |
| `WHERE date(created_at) = '2026-11-01'` | `WHERE created_at >= '2026-11-01' AND created_at < '2026-11-02'` |
| `WHERE amount * 1.18 > 118` | `WHERE 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](https://www.postgresql.org/docs/current/indexes-expressional.html)). 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](https://www.aifordatabase.com/blog/postgresql-explain-query/) 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?

| Term | Meaning | Example |
| --- | --- | --- |
| Expression | anything that produces a value | `amount * 1.18` |
| Predicate | an expression that produces TRUE, FALSE or UNKNOWN | `amount > 100` |
| Search condition | one or more predicates joined by AND, OR, NOT | `amount > 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

*   `= NULL` instead of `IS NULL` returns nothing.
*   `<>` and `NOT IN` drop NULL rows; use `IS DISTINCT FROM` or `NOT EXISTS`.
*   `BETWEEN` on timestamps includes the end value; prefer a half-open range.
*   `OR` without parentheses: `a AND b OR c` means `(a AND b) OR c`.
*   Functions on indexed columns make predicates non-sargable.

For more syntax at a glance, keep the [SQL cheat sheet](https://www.aifordatabase.com/blog/sql-cheat-sheet/) open.

D

Written by [Dhrumil Barot](https://www.aifordatabase.com/about/#founder)

Dhrumil is an enterprise analytics expert. Dhrumil built AI for Database so anyone on a team can get answers from live company data in plain English, without waiting on a data team.

[LinkedIn](https://www.linkedin.com/in/bdhrumil)[X](https://x.com/fyidhrumil)

## 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).

Read next

*   [WHAT IS AN AI DATABASE? DEFINITION, TYPES AND EXAMPLES →](https://www.aifordatabase.com/blog/what-is-an-ai-database/)
*   [DASHBOARD TYPES: 7 EXAMPLES WITH TILES, REFRESH AND SQL →](https://www.aifordatabase.com/blog/dashboard-types-examples/)
*   [WHAT IS A PARAMETERIZED REPORT? DEFINITION AND EXAMPLES →](https://www.aifordatabase.com/blog/parameterized-report/)
*   [POSTGRESQL CAST: CONVERT TYPES WITH CAST AND :: →](https://www.aifordatabase.com/blog/postgresql-cast/)

Source: https://www.aifordatabase.com/blog/predicate-in-sql/
