Part 76: Subqueries in the FROM Clause (Derived Tables)
Using the result of a subquery as a temporary virtual table inside the FROM clause.
1. Syntax
-- Calculate the average of department totals:
SELECT AVG(dept_summary.dept_total) AS avg_dept_payroll
FROM (
SELECT department, SUM(salary) AS dept_total
FROM employees
GROUP BY department
) AS dept_summary; -- Derived tables MUST have an alias!
Key Takeaways
- All derived tables in the
FROMclause require an explicit alias.
In Part 77, we will explore Combining Results with UNION and UNION ALL!

