You are on page 1of 5

What is a Derived Table?

www.essentialSQL.com
Derived Table

• A derived table is a query used in the FROM


clause.
• It acts as a table since its results are in the
form of rows and columns.
• A derived table is a subquery
Anatomy of a Derived Table

Derived Table enclosed in


parenthesis ( )

Alias columns so you can


reference them in the outer
query.
SELECT TerritoryID,
AverageBonus
FROM (SELECT TerritoryID, All derived tables must have a
Avg(Bonus) AS AverageBonus table alias – no exceptions
FROM Sales.SalesPerson
GROUP BY TerritoryID) AS TerritorySummary
Derived Table Step-By-Step

SELECT TerritoryID, TerritorySummary


Avg(Bonus) AS AverageBonus TerritoryID AverageBonus
FROM Sales.SalesPerson 1 4133.33
GROUP BY TerritoryID 2 4100.00

SELECT TerritoryID, SELECT TerritoryID,


AverageBonus AverageBonus
FROM (SELECT TerritoryID, FROM TerritorySummary
Avg(Bonus) AS AverageBonus
FROM Sales.SalesPerson
GROUP BY TerritoryID)
AS TerritorySummary
Examples

You might also like