1

我有以下查询,它为我提供了给定标题的提供者:

SELECT DISTINCT(provider) FROM 
    (SELECT title, provider FROM financials_raw 
        UNION 
        SELECT title, provider from sales_raw
    ) combined 
        WHERE title = 'Home'

但是,这也将返回 NULL 提供程序结果,我将如何排除所有 null 结果?

4

1 回答 1

13

除了我上面的评论之外,以下查询将完成相同的操作,但效率更高(因为不需要的记录UNION在随后从物化表中过滤之前不会首先加入到操作中):

  SELECT provider FROM financials_raw WHERE title = 'Home' AND provider IS NOT NULL
UNION
  SELECT provider FROM      sales_raw WHERE title = 'Home' AND provider IS NOT NULL

请注意UNION(没有ALL限定)意味着DISTINCT.

于 2012-05-29T18:23:30.160 回答