Real Project: Multi-Table Reporting Query
Congratulations! You've finished **Phase 3**. You've mastered the most difficult structural concept in SQL.
Today, we're building a "Full Customer Snapshot" report.
The Requirement
The Marketing VP wants a report that shows:
The Multi-Table Solution
SELECT
c.name,
SUM(o.total_price) AS lifetime_spend,
MIN(o.order_date) AS first_order,
am.manager_name
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
LEFT JOIN account_managers am ON c.manager_id = am.id
GROUP BY c.name, am.manager_name
ORDER BY lifetime_spend DESC;
Why we used LEFT JOIN
We want to see *all* customers, even if they haven't been assigned a manager yet or haven't made an order. Using an `INNER JOIN` here would hide potential new customers!
What's Next?
You can now connect the whole database together. In **Phase 4 (Days 46–60)**, we'll learn how to write "Queries within Queries" (**Subqueries**) and use **CTEs** to make your code look senior and professional.
See you in Phase 4!