Updated on 2024-12-13 GMT+08:00

Subqueries

EXISTS

The EXISTS predicate determines whether to return any row.

SELECT name FROM nation WHERE EXISTS (SELECT * FROM region WHERE region.regionkey = nation.regionkey)

IN

It determines whether any value generated by a subquery is equal to a given expression.

The IN result complies with the standard null rule.

Only one column must be generated for a subquery.

SELECT name FROM nation WHERE regionkey IN (SELECT regionkey FROM region)