The INTERSECT operator returns rows that appear in both result sets. Unlike UNION, which combines and deduplicates results, INTERSECT narrows them to only the overlap.
Syntax
select_statement INTERSECT select_statementEach select_statement is a SELECT statement that does not include an ORDER BY or FORUPDATE clause.
How it works
INTERSECT computes the set intersection of rows returned by two SELECT statements. A row appears in the output only if it exists in both result sets. Duplicate rows are removed from the result automatically.
Operator precedence
When a query contains multiple set operators, INTERSECT binds more tightly than UNION. The expression:
A UNION B INTERSECT Cis evaluated as:
A UNION (B INTERSECT C)Multiple INTERSECT operators at the same level are evaluated left to right. Use parentheses to make the evaluation order explicit when mixing INTERSECT with UNION.
Limitations
Each
SELECTstatement cannot contain anORDER BYorFORUPDATEclause.