INTERSECT Operator - SQL


Overview


The INTERSECT Operator in SQL is used to return the common rows from two or more SELECT statements. It retrieves only the rows that appear in both result sets.

Syntax:

SELECT column1, column2
FROM table1
INTERSECT
SELECT column1, column2
FROM table2

SELECT column1, column2, ... FROM table1 specifies the columns to select from the first table.

INTERSECT combines the results of the two SELECT statements, returning only the common rows.

SELECT column1, column2, ... FROM table2 specifies the columns to select from the second table. The number and data types of columns in both SELECT statements must match.