Skip to content
Advertisement

How to check if several values are in a list in BigQuery

Is there a way to make this clause more compact?

SELECT campaign
       ,event_list
FROM `adobe_analytics.raw_data_20200*`
WHERE campaign IS NOT NULL  -- What does it mean when a campaign is null in Adobe_analytics
AND
(
"1" IN UNNEST(split(event_list,","))
OR "2" IN UNNEST(split(event_list,","))
OR "3" IN UNNEST(split(event_list,","))
)

Something like :

SELECT campaign
   ,event_list
FROM `adobe_analytics.raw_data_20200*`
WHERE campaign IS NOT NULL
AND ("1" OR "2" OR "3") IN UNNEST(split(event_list,","))

Advertisement

Answer

I would use exists:

SELECT campaign, event_list
FROM `adobe_analytics.raw_data_20200*` rd
WHERE campaign IS NOT NULL AND
      EXISTS (SELECT 1
              FROM UNNEST(SPLIT(rd.event_list)) el
              WHERE el IN ('1', '2', '3')
             );
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement