INTERSECT is a set-operation operator that produces the common rows from two SELECT statements. Each input query must return the same number of columns, and each column pair must be of compatible data types. By default the operator performs INTERSECT DISTINCT, meaning duplicate rows are eliminated after the intersection is computed. Some systems also allow INTERSECT ALL to keep duplicates. The column names of the first SELECT are preserved in the final result.The comparison treats NULL as a comparable value, so a row containing NULLs is returned if an identical row (including NULL in the same positions) exists in both result sets. ORDER BY can be applied only once, to the combined result, and must reference output column positions or names. INTERSECT is evaluated after FROM, WHERE, GROUP BY, and HAVING but before ORDER BY and LIMIT clauses. Because it forces a deduplication step, it can be more expensive than INNER JOIN on primary keys when large row counts are involved.
UNION, UNION ALL, EXCEPT, MINUS, INNER JOIN, DISTINCT, SET OPERATORS
SQL:1999
UNION returns all distinct rows that appear in either query, whereas INTERSECT returns only the rows present in both queries.
Yes. A row containing NULLs is returned if an identical row with NULL in the same columns exists in both result sets.
Yes. Chain multiple INTERSECT operators: `query1 INTERSECT query2 INTERSECT query3`, keeping column counts and data types aligned.
Use the optional `INTERSECT ALL` if your database supports it. Otherwise, duplicates are removed by default.