Derived tables

Intermediate SQL Server

Ginger Grant

Instructor

What are Derived tables?

  • Query which is treated like a temporary table
  • Always contained within the main query
  • They are specified in the FROM clause
  • Can contain intermediate calculations to be used the main query or different joins than in the main query
Intermediate SQL Server

Derived tables in T-SQL

SELECT a.* FROM Kidney a
-- This derived table computes the Average age joined to the actual table 
JOIN (SELECT AVG(Age) AS AverageAge 
      FROM Kidney) b 
ON a.Age = b.AverageAge
Intermediate SQL Server

Let's practice!

Intermediate SQL Server

Preparing Video For Download...