Intermediate

Real Project: Multi-Table Reporting Query

SQL Mastery Team
March 7, 2026
6 min read

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:

  • Customer Name
  • Total Lifetime Spend
  • Their Favorite Category (most purchased)
  • Date of their Very First Order
  • The Name of their Account Manager
  • 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!

    Ready to put your knowledge into practice?

    Join SQL Mastery and learn through interactive exercises.