codegurukool.com · Free coding tutorials & online compiler

Home › SQL Tutorial › SQL EXISTS, ANY and ALL

SQL EXISTS, ANY and ALL

Test against a subquery.

EXISTS is true when the subquery returns at least one row. ANY and ALL compare a value with a list of results: true for at least one, or true for every one.

Example code

SELECT name FROM Customers c
WHERE EXISTS (
  SELECT 1 FROM Orders o
  WHERE o.customer_id = c.id
);

Run this code in the online editor

← SQL CASESQL CREATE TABLE and constraints →