【问题标题】:BigQuery not returning missing NULL rows in LEFT JOINBigQuery 未在 LEFT JOIN 中返回缺失的 NULL 行
【发布时间】: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

【问题讨论】:

  • 您的代码是正确的,因此您的问题无法重现。

标签: sql google-bigquery


【解决方案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 
                 );

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-26
    • 2015-01-13
    • 2015-01-30
    • 2010-11-05
    • 1970-01-01
    • 2020-04-25
    相关资源
    最近更新 更多