BigQuery 未在 LEFT JOIN 中返回缺失的 NULL 行

Posted

技术标签:

【中文标题】BigQuery 未在 LEFT JOIN 中返回缺失的 NULL 行【英文标题】:BigQuery not returning missing NULL rows in LEFT JOIN 【发布时间】:2021-08-18 23:58:26 【问题描述】:

我们如何让 BigQuery 返回左连接中存在于表 A 中但在表 B 中为 NULL 的行?

当我运行它时,下面不会返回任何行,即使表 A 中有不在表 B 中的值

-- find missing users. return rows which exist in A but not in B
select          a.user_id
from            table_a a  
left outer join table_b b on a.user_id = b.user_id 
where           b.user_id is null

【问题讨论】:

您的代码是正确的,因此您的问题无法重现。 【参考方案1】:

根据您所说的,您的查询应该有效。不过,你也可以直接使用NOT EXISTS

select a.user_id
from  table_a a  
where not exists (select 1
                  from table_b b 
                  where a.user_id = b.user_id 
                 );

【讨论】:

以上是关于BigQuery 未在 LEFT JOIN 中返回缺失的 NULL 行的主要内容,如果未能解决你的问题,请参考以下文章