ANY Operator

SQL · SQL Subqueries

Theory

ANY compares a value with the values returned by a subquery, and the condition is TRUE if it holds for at least one of them. salary > ANY (SELECT salary FROM interns) keeps employees who earn more than at least one intern, which means more than the lowest intern salary. SOME is an exact synonym for ANY.

With equality, = ANY (subquery) means exactly the same as IN (subquery). If the subquery returns no rows, ANY is FALSE for every outer row. If there is no match but the list contains a NULL, the result is UNKNOWN and the row is dropped. The equivalent salary > (SELECT MIN(salary) FROM interns) is often clearer and is what you write on engines without ANY, such as SQLite. Beware the English trap: <> ANY is TRUE if the value differs from at least one item, which is almost always TRUE; to mean "not in the list" use <> ALL or NOT IN.

Why we use it

Some rules only need to beat one value in a set: cheaper than at least one competitor, scored above any of the pass marks. ANY expresses "at least one" without writing a separate MIN or MAX query.

When to use it

Use ANY for "at least one" comparisons against a subquery, and = ANY interchangeably with IN. Prefer > MIN() or < MAX() when readability matters, and use ALL when every value must satisfy the condition.

How it works

  1. Take an outer row
  2. Run the subquery to get the list of values
  3. Compare the outer value with each item
  4. Does the comparison hold for at least one value? Yes: Keep the row. No: Discard the row.
  5. Move to the next row

Syntax

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

Example

SELECT name FROM employees
WHERE salary > ANY (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