Saturday, December 5, 2009

Derived Tables in SQL

 SELECT LastName, FirstName
 FROM
  (SELECT * FROM Employee
   WHERE State = "NY") AS EmployeeDerivedTable
 WHERE LastName = "Smith"
 ORDER BY FirstName

What we are doing is first getting the result set from
our derived table (the SELECT statement in the FROM clause).  Once we have
that resultset, it is as though it was a table in itself.  We then perform
the SELECT on the derived table, returning our results.

0 comments: