ALL Operator

SQL · SQL Subqueries

Theory

ALL compares a value with every value returned by a subquery, and the condition is TRUE only if it holds for all of them. salary > ALL (SELECT salary FROM interns) keeps employees who earn more than every intern, which in practice means more than the highest intern salary. It works with any comparison operator: =, <>, <, >, <=, >=.

Two edge cases matter. If the subquery returns no rows, ALL is TRUE for every outer row, which can surprise you. If the subquery contains a NULL and no value fails the test, the result is UNKNOWN and the row is dropped. Because of this, many people write the clearer equivalent salary > (SELECT MAX(salary) FROM interns), which is also what you must use on engines without ALL, such as SQLite. Note that <> ALL means the same as NOT IN.

Why we use it

Some rules must beat or meet every value in a set: higher than all competitor prices, earlier than all deadlines. ALL states "for every value" directly in the comparison.

When to use it

Use ALL when the condition must hold against every value of a subquery. Often > MAX() or < MIN() is easier to read and handles empty sets more predictably. For "at least one" logic, use ANY.

How it works

  1. Take an outer row
  2. Run the subquery to get the list of values
  3. Is the list empty? Yes: ALL is TRUE: keep the row. No: Compare against each value.
  4. Does the comparison hold for every value? Yes: Keep the row. No: Discard the row.
  5. Move to the next row

Syntax

SELECT columns FROM table
WHERE column > ALL (subquery);

Example

SELECT name FROM employees
WHERE salary > ALL (SELECT salary FROM interns);

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic