EXISTS

The exists clause tests for the existence of any rows in a subquery.

Syntax

SELECT <column_name> [ ,... ]
FROM <table_name>
WHERE EXISTS (<subquery>)

Arguments

Parameter

Description

column_name

The columns to retrieve

table_name

The table from which to retrieve the data.

Returns

Returns TRUE if the subquery returns one or more rows, and FALSE if the subquery returns no rows

Examples

SELECT
  employee_id,
  employee_name
FROM
  employees
WHERE
  EXISTS (
    SELECT
      1
    FROM
      departments
    WHERE
      departments.department_id = employees.department_id
  );