A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.snowflake.com/en/sql-reference/operators-subquery below:

Website Navigation


Subquery operators | Snowflake Documentation

Subquery operators

A subquery is a query within another query. Subquery operators perform operations on the values produced by subqueries.

Snowflake supports the following subquery operators:

ALL / ANY

The ALL and ANY keywords can be used to apply a comparison operator to the values produced by a subquery (which can return more than one row).

Syntax
<expr> comparisonOperator { ALL | ANY } ( <query> )

Copy

Where:

comparisonOperator ::=
  { = | != | > | >= | < | <= }

Copy

Usage notes Examples

Use a != ALL subquery to find the departments that have no employees:

SELECT department_id
  FROM departments d
  WHERE d.department_id != ALL (
    SELECT e.department_id
      FROM employees e);

Copy

[ NOT ] EXISTS

An EXISTS subquery is a Boolean expression that can appear in a WHERE or HAVING clause, or in any function that operates on a Boolean expression:

Syntax
[ NOT ] EXISTS ( <query> )

Copy

Usage notes Examples

Use a correlated NOT EXISTS subquery to find the departments that have no employees:

SELECT department_id
  FROM departments d
  WHERE NOT EXISTS (
    SELECT 1
      FROM employees e
      WHERE e.department_id = d.department_id);

Copy

[ NOT ] IN

The IN and NOT IN operators check whether an expression is included in the values produced by a subquery.

Syntax
<expr> [ NOT ] IN ( <query> )

Copy

Usage notes Examples

Use a NOT IN subquery that is equivalent to the != ALL subquery example (earlier in this topic) to find the departments that have no employees:

SELECT department_id
  FROM departments d
  WHERE d.department_id NOT IN (
    SELECT e.department_id
      FROM employees e);

Copy


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4