Introduction
INTERSECT helps find rows that appear in both tables or queries. It shows only the common data.
Jump into concepts and practice - no test required
SELECT column_list FROM table1 INTERSECT SELECT column_list FROM table2;
SELECT name FROM employees_2023 INTERSECT SELECT name FROM employees_2024;
SELECT product_id, product_name FROM store_a INTERSECT SELECT product_id, product_name FROM store_b;
SELECT city FROM customers_north INTERSECT SELECT city FROM customers_south;
CREATE TABLE fruits_a (name VARCHAR(20)); CREATE TABLE fruits_b (name VARCHAR(20)); INSERT INTO fruits_a VALUES ('Apple'), ('Banana'), ('Cherry'); INSERT INTO fruits_b VALUES ('Banana'), ('Cherry'), ('Date'); SELECT name FROM fruits_a INTERSECT SELECT name FROM fruits_b;
INTERSECT operator do?TableA and TableB with the same columns id and name?Employees1:Employees2:SELECT id, name FROM Employees1 INTERSECT SELECT id, name FROM Employees2;
SELECT id, name FROM Customers INTERSECT SELECT id, name FROM Orders;
ProductsA with columns product_id, name, priceProductsB with columns product_id, name, priceproduct_id and name, ignoring price differences.