Skip to content

INTERSECT

  • query_1: It specifies the first SELECT statement. It is the initial set of data that will be compared to the data provided in query_2 for any identical rows.
  • query_2: This is the second SELECT statement. It defines the second set of data which is compared with query_1’s results. Only common rows between both queries will be included in the final output.
SELECT column_name FROM table1
INTERSECT
SELECT column_name FROM table2;
column_name
-------------
Value1
Value2
(2 rows)

The INTERSECT function in SQL is used to return the common rows from two or more SELECT statements. The above example selects a specific column from table1 and table2, and the INTERSECT command returns only the common rows that appear in both tables.