Aashis Aashu
Aashis Aashu

Reputation: 61

How to use MINUS in google bigquery?

I am trying to do MINUS on 2 tables which have same schema in big-query.As I understand MINUS is not working in biquery

Upvotes: 0

Views: 6155

Answers (2)

Aashis Aashu
Aashis Aashu

Reputation: 61

I see that there is EXCEPT set operator in Big Query for Standard SQL. The EXCEPT operator returns rows from the left input query that are not present in the right input query. This is similar to what the MINUS does in ORACLE/MySQL SELECT fieldId from dataset.table1 except DISTINCT SELECT fieldId from dataset.table2

Note: the datatype of both the columns should be same in both the tables

Upvotes: 1

Willian Fuks
Willian Fuks

Reputation: 11797

You can do something like:

SELECT 
   field
FROM `project_id.dataset.tableA` A
WHERE NOT EXISTS(SELECT 1 FROM `project_id.dataset.tableB` b WHERE a.field = b.field)

Upvotes: 1

Related Questions