Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MINUS functionality in BigQuery database

I am new to BigQuery database.

Like in Oracle database MINUS operator what is the same functionality in BigQuery? I did not find MINUS operator in BigQuery.

Oracle --> Minus
BigQuery --> ??

like image 980
user3782531 Avatar asked Jun 27 '14 10:06

user3782531


2 Answers

Though there is no MINUS function in BigQuery, you can use a LEFT OUTER JOIN as an alternative.

 SELECT name, uid FROM a
 MINUS
 SELECT name, uid FROM b

Can be written as:

SELECT a.name, a.uid
FROM a LEFT OUTER JOIN b ON a.name= b.name AND a.uid= b.uid
WHERE b.name IS NULL
like image 150
Shayan Masood Avatar answered Oct 03 '22 17:10

Shayan Masood


with whole as
( select 1 as id, 'One' as value
  union all
  select 2 as id, 'Two' as value
  union all
  select 3 as id, 'Three' as value
  ),
  sub_set as
  (
   select 1 as id, 'One' as value
  union all
  select 2 as id, 'Two' as value
  )
  select * from whole
  except distinct
  select * from sub_set

Result was

    3 Three

Refer: https://cloud.google.com/bigquery/docs/reference/standard-sql/query-syntax#except

I am getting the error EXCEPT ALL is not supported, DISTINCT worked. Hope this helps.

like image 40
Vamsi Namburu Avatar answered Oct 03 '22 15:10

Vamsi Namburu