Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk2 min

SQL ALL With an Empty Subquery: What to Know

SQL ALL is true for an empty subquery because no returned value can disprove the comparison. ANY and SOME are false when there are no values to match.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In SQL, the quantified predicate ALL makes a comparison true when its subquery returns no rows. For example, 10 > ALL (SELECT value FROM t) is true if that subquery is empty. This rule belongs to SQL’s ALL quantifier—not to comparison operators in every programming language.

What SQL ALL means

ALL combines a comparison operator with a subquery. The comparison must hold for every value the subquery returns. So 10 > ALL (SELECT value FROM t) asks whether 10 is greater than every returned value.

As an Amazon Associate I earn from qualifying purchases.

If the subquery returns no values, there is no value that violates the condition. In logic, a statement that applies to every member of an empty set is true: there is no counterexample. Firebird’s documentation on quantified predicates explicitly describes this empty-set behavior.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How ALL differs from ANY and SOME

ANY and SOME ask whether the comparison holds for at least one value returned by the subquery. With no values, there cannot be a matching value, so the result is false. The contrast is:

Predicate Question Result for an empty subquery
ALL Does the comparison hold for every returned value? True
ANY or SOME Does the comparison hold for at least one returned value? False

For example, if the subquery is empty, 10 > ALL (SELECT value FROM t) is true, while 10 > ANY (SELECT value FROM t) is false. The SQL-99 reference on searching with subqueries describes the same distinction.

Why NULL makes a different case

An empty result and a non-empty result containing NULL are not equivalent. SQL comparisons involving NULL can evaluate to UNKNOWN, rather than true or false. Consequently, a comparison quantified over rows that include NULL may not produce the simple result you would get from ordinary non-NULL values. Firebird and the SQL-99 reference document this distinction; consult the documentation for your database when NULLs or dialect-specific behavior matter.

Why this is not a universal comparison-operator rule

The phrase “comparison operator” can mean different things across languages. SQL’s ALL is a quantifier used with an operator such as > or =; it is not itself an operator like >.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

PowerShell provides a useful contrast. Microsoft’s PowerShell 7.4 comparison-operator documentation says that a scalar on the left produces a Boolean, while a collection on the left produces the matching elements; if there are no matches, the result is an empty array. That is a different behavior from SQL’s quantified predicate.

C++ also uses the term “three-way comparison operator” for <=>, sometimes called the spaceship operator. It is a separate language feature, not SQL’s ALL predicate.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Check your database’s syntax

The empty-set rule explains the logic of SQL quantified comparisons, but accepted syntax and supported operators can vary by database. Firebird, for example, documents its own supported comparison operators and specifies that its quantifiers take a subselect. Check the reference for the database you use before adapting an example.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.