EXISTS 条件 - Amazon Redshift
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

EXISTS 条件

EXISTS 条件测试子查询中是否存在行,并在子查询返回至少一个行时返回 true。如果指定 NOT,此条件将在子查询未返回任何行时返回 true。

语法

[ NOT ] EXISTS (table_subquery)

参数

EXISTS

table_subquery 返回至少一行时,为 true。

NOT EXISTS

table_subquery 未返回任何行时,为 true。

table_subquery

计算结果为包含一个或多个列和一个或多个行的表的子查询。

示例

此示例针对具有任何类型的销售的日期返回所有日期标识符,一次返回一个日期:

select dateid from date where exists ( select 1 from sales where date.dateid = sales.dateid ) order by dateid; dateid -------- 1827 1828 1829 ...