INTERSECT
INTERSECT is a SQL statement in the Set Operations category. Returns rows that appear in BOTH query results. Supported in PostgreSQL, SQL Server, Oracle. The syntax is SELECT columns FROM table1 INTERSECT SELECT columns FROM table2;. It returns common rows. A typical example: SELECT product_id FROM products INTERSECT SELECT product_id FROM discontinued_products; -- Products that are in both tables A close relative is UNION, which combines results from two queries, removing duplicate rows. Each SELECT must have the same number of columns. A close relative is UNION ALL, which like UNION but does NOT remove duplicate rows. Faster because no dedup is needed. A close relative is EXCEPT / MINUS, which returns rows from the first query that do NOT appear in the second query results. More about this category: Set-based operations — UNION, UNION ALL, INTERSECT, EXCEPT. Related Set Operations entries: UNION, UNION ALL, EXCEPT / MINUS, INTERSECT ALL / EXCEPT ALL, Ordering Set Operations, TABLE Keyword, Set Operation Precedence, Set Operation with ORDER BY.