🔁 SQL UNION, INTERSECT, MINUS Explained

🔁 SQL Set Operators: UNION, INTERSECT, MINUS

Set operators combine the results of two or more SELECT queries. Let's see how UNION, INTERSECT, and MINUS work using Bangladeshi employee examples.

📋 Sample Tables

sales_team

name department
ArifSales
RafiSales
NasrinSales

marketing_team

name department
NasrinMarketing
RituMarketing
FarukMarketing

1️⃣ UNION

Goal: Combine all unique employee names from both teams.

SELECT name FROM sales_team
UNION
SELECT name FROM marketing_team;

Output:

name
Arif
Faruk
Nasrin
Rafi
Ritu

2️⃣ INTERSECT

Goal: Find names common in both teams (same name must exist in both queries).

SELECT name FROM sales_team
INTERSECT
SELECT name FROM marketing_team;

Output:

name
Nasrin

3️⃣ MINUS (or EXCEPT)

Goal: Find employees who are in sales_team but not in marketing_team.

SELECT name FROM sales_team
MINUS
SELECT name FROM marketing_team;

Output:

name
Arif
Rafi
📌 Summary:
  • UNION: Combines unique rows from both queries.
  • INTERSECT: Returns only common rows in both queries.
  • MINUS: Returns rows in first query that are not in the second.
  • ⚠ Note: Some databases use EXCEPT instead of MINUS.
SQL UNION tutorial, SQL INTERSECT example, SQL MINUS or EXCEPT, set operators in SQL, Bangladeshi employee SQL example, MySQL combine queries, SQL union intersect difference, beginner SQL joins

āĻ•োāύ āĻŽāύ্āϤāĻŦ্āϝ āύেāχ:

āĻāĻ•āϟি āĻŽāύ্āϤāĻŦ্āϝ āĻĒোāϏ্āϟ āĻ•āϰুāύ