The INTERSECT syntax is used to combine the analysis results of two SELECT statements, and return only the rows that exist in both result sets.
Syntax Format
* | SELECT [column name(KEY)] FROM table1 INTERSECT SELECT [column name(KEY)] FROM table2
The analysis results of each SELECT statement should have the same number of columns and the same field types to be combined.
If the SELECT result contains duplicate rows, INTERSECT retains only one instance of each.
Syntax Example
Combine two tables with only one column to get the rows that exist in both of them. Among them, the first table has only one row with a value of 13, and the second table has two rows with values of -42 and 13, respectively.
* | SELECT * FROM (VALUES 13)
INTERSECT
SELECT * FROM (VALUES 42,13)
Return result: