đŸ§Ē SQL Practice: Combine and Compare Data

đŸ§Ē SQL Practice: Combine and Compare Queries

Use SQL set operators like UNION, INTERSECT, and MINUS to merge and compare data from different sources.

📋 Sample Tables

sales_team

name region
ArifDhaka
RafiChattogram
NasrinDhaka

marketing_team

name region
NasrinDhaka
RituKhulna
FarukChattogram

🧠 Practice 1: Combine All Unique Employees

Goal: Show all distinct employee names from both teams.

SELECT name FROM sales_team
UNION
SELECT name FROM marketing_team;

Output:

name
Arif
Faruk
Nasrin
Rafi
Ritu

🧠 Practice 2: Find Common Employees

Goal: Find employees who work in both teams.

SELECT name FROM sales_team
INTERSECT
SELECT name FROM marketing_team;

Output:

name
Nasrin

🧠 Practice 3: Find Sales-Only Members

Goal: Show employees in sales team but not in marketing.

SELECT name FROM sales_team
MINUS
SELECT name FROM marketing_team;

Output:

name
Arif
Rafi

🧠 Practice 4: Combine with Duplicates (UNION ALL)

Goal: Combine names from both teams including duplicates.

SELECT name FROM sales_team
UNION ALL
SELECT name FROM marketing_team;

Output: Includes "Nasrin" twice since she’s in both.

name
Arif
Rafi
Nasrin
Nasrin
Ritu
Faruk
📌 Practice Tips:
  • Try changing regions or adding new employees and rerun the queries.
  • Try using ORDER BY after UNION for sorting.
  • Use UNION ALL to keep duplicates if needed.
SQL UNION INTERSECT MINUS practice, SQL query comparison, combine SQL result sets, MySQL set operations, SQL for beginners Bangladeshi example, employee SQL challenge

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

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