INTERSECT operator in BigQuery

The INTERSECT operator in BigQuery is used to return only the rows that are common between the result sets of two or more SELECT queries.

In other words, it returns the overlapping records that appear in all queries involved in the INTERSECT operation.

Key Rules for INTERSECT

SQL Syntax

SELECT column1, column2, ...
FROM `project.dataset.table1`
WHERE condition

INTERSECT DISTINCT

SELECT column1, column2, ...
FROM `project.dataset.table2`
WHERE condition;    

A simplified form of the INTERSECT syntax is shown below:

SQL

SELECT column1, column2, ..., columnN
FROM table_name1
[WHERE conditions]

INTERSECT

SELECT column1, column2, ..., columnN
FROM table_name2
[WHERE conditions];    

Example: Find common customers in two regions.

SQL

SELECT customer_id
FROM `project.dataset.sales_india`

INTERSECT

SELECT customer_id
FROM `project.dataset.sales_usa`;    

Result