代码之家  ›  专栏  ›  技术社区  ›  crazy8

BigQuery在左联接中未返回缺少的空行

  •  0
  • crazy8  · 技术社区  · 4 年前

    如何让BigQuery返回表a中存在但表B中为空的左联接中的行?

    下面的代码在我运行时不返回任何行,即使表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
    
    0 回复  |  直到 4 年前
        1
  •  0
  •   Gordon Linoff    4 年前

    根据您所说的,您的查询应该是有效的。但是,您也可以使用 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 
                     );