গল্প — Online Shopping
একটি e-commerce company-এর data আলাদা table-এ থাকে।
| customer_id | customer_name | city |
|---|---|---|
| 1 | Rahim | Dhaka |
| 2 | Karim | Chittagong |
| 3 | Nila | Dhaka |
| order_id | customer_id | product_id | quantity |
|---|---|---|---|
| 101 | 1 | 501 | 2 |
| 102 | 2 | 502 | 1 |
| 103 | 1 | 503 | 3 |
| product_id | product_name | category_id | price |
|---|---|---|---|
| 501 | Laptop | 10 | 80000 |
| 502 | Mouse | 11 | 1500 |
| 503 | Keyboard | 11 | 2500 |
| category_id | category_name |
|---|---|
| 10 | Electronics |
| 11 | Accessories |
Rahim কী product কিনেছে? → customers + orders + products
Rahim কোন category-এর product কিনেছে? → উপরের তিনটি + categories
কেন এক table-এ সব রাখব না?
নাম/city ১০০বার duplicate → storage waste, inconsistency, update কঠিন।
1 → 2 → 3 → 4 Table
Big Visual Diagram
Multi-table JOIN কী?
যখন ৩ বা তার বেশি related table JOIN করে একটি result তৈরি হয় — Multi-table JOIN।
আগে Relationship আঁকো
২-Table Revision
c = customer · o = order · key = customer_id।
৩-Table JOIN
Animated Join Frames
৪-Table JOIN
| customer_name | order_id | product_name | category_name |
|---|---|---|---|
| Rahim | 101 | Laptop | Electronics |
| Karim | 102 | Mouse | Accessories |
| Rahim | 103 | Keyboard | Accessories |
কীভাবে Query পড়া/লেখা
- কী information চাই?
- কোন table-এ আছে?
- কীভাবে connected?
- কোন JOIN type?
- Final output কী?
INNER JOIN Chain
প্রতিটি ধাপে matching চাই। Product না থাকলে সেই order বাদ।
LEFT JOIN Chain
সব customer চাই — order না থাকলেও।
| customer | order | product |
|---|---|---|
| Rahim | 101 | Laptop |
| Karim | 102 | Mouse |
| Nila | NULL | NULL |
Mixed JOIN Types
+ WHERE
+ GROUP BY
+ SUM Sales
+ HAVING
+ ORDER BY
Complete Business Report
Case Study Schema
Online shop: customers (id, name, city, country) · orders (id, customer_id, product_id, qty, order_date) · products · categories — ~২০ rows lab dataset।
CREATE / INSERT Lab
১৫ Progressive Challenges
Build-the-Query Card Game
JOIN Chain Visualizer (Blueprint)
Intermediate Results
Common Mistakes (১৫)
- Wrong columns in ON
- Forgetting ON
- Wrong alias
- Ambiguous column names
- SELECT *
- Wrong starting table
- Wrong JOIN type
- Broken relationship chain
- Joining unrelated tables
- Unexpected duplicate rows
- Missing NULL (need LEFT)
- Wrong WHERE
- Wrong GROUP BY
- Wrong HAVING
- Unintentional row multiplication
Duplicate / Row Growth
1:1 · 1:N · M:N
1:1
Person → Passport
1:N
Customer → Orders
School Example
Hospital Example
Company HR Example
Employee কোন department, manager, location-এ?
SELF JOIN + Multi-table
Conceptual Execution Flow
Comparison Tables
| Topic | A | B |
|---|---|---|
| 2-table vs Multi | ২ table | ৩+ table chain |
| INNER vs LEFT multi | শুধু match | বাম সব + NULL |
| SELF vs Multi | এক table roles | আলাদা tables |
| WHERE vs HAVING | row filter | group filter |
| JOIN vs UNION | columns পাশাপাশি | rows নিচে নিচে |
| PK vs FK | unique identity | অন্য table reference |
| 1:1 / 1:N / M:N | passport / orders / junction | — |
Industry Use
- Analyst: sales, customer, KPI
- Data Scientist: feature/dataset build
- Data Engineer: ETL / warehouse queries
- BI: Power BI / Looker datasets
- Finance / HR: revenue, employee reports
Performance Basics
- অনেক JOIN expensive হতে পারে
- Index PK/FK / join columns
- অপ্রয়োজনীয় table/column বাদ
- Filter early (WHERE)
- Row multiplication বুঝো
- শুরুতে
EXPLAINদেখো
Playground UI Blueprint
Interactive Animation Blueprint
Predict the Row Count
Query Builder Game
Debugging Game
Live Class Activities (২০)
Mini Project — E-Commerce Analytics
- Customer order history
- Customer + Product
- Customer + Product + Category
- Customer total spending
- Category total sales
- City-wise sales
- Top 10 customers
- Top 10 products
- Products never ordered
- Customers who never ordered
- Categories with sales > X
- Monthly sales summary
Interview Top 30
MCQ (২৫+)
Viva
Homework
প্রশ্ন (২০):
- 2-table customer-order
- Order-product
- Product-category
- 3-table customer-product
- 4-table + category
- Dhaka filter
- Category order counts
- Category sales
- Customer spending
- City sales
- HAVING sales>X
- ORDER BY top categories
- LIMIT top 3 customers
- Customers no orders
- Products never ordered
- School 4-table
- Hospital 4-table
- SELF+dept report
- Mixed LEFT/INNER explain
- Full business report
Final Cheat Sheet
MULTI-TABLE JOIN
3+ RELATED TABLES → IDENTIFY RELATIONSHIPS → JOIN CHAIN
→ FILTER → GROUP → SUMMARIZE → SORT → REPORT
SELECT c.customer_name, p.product_name, cat.category_name
FROM customers c
JOIN orders o ON c.customer_id = o.customer_id
JOIN products p ON o.product_id = p.product_id
JOIN categories cat ON p.category_id = cat.category_id;
Memory: Customer → Order → Product → Category