A subquery is a SELECT statement that is nested within another statement. Subqueries are usually used in the WHERE clause as a way to filter out certain rows returned in the result set of the outer query.
Derived tables
A derived table is basically a subquery, except it is always in the FROM clause of a SQL statement. The reason it is called a derived table is because it essentially functions as a table.
Example of a derived table
select max(age)
from (
-- this part of the query is a derived table:
select age from table
) as Age -- must give derived table an alias
Summary of the difference between derived tables and subqueries
- derived tables are used in the FROM clause
- subqueries are used in the WHERE clause, but can also be used to select from one table and insert into another.
Read full article from difference between a derived table and a subquery
Derived tables
A derived table is basically a subquery, except it is always in the FROM clause of a SQL statement. The reason it is called a derived table is because it essentially functions as a table.
Example of a derived table
select max(age)
from (
-- this part of the query is a derived table:
select age from table
) as Age -- must give derived table an alias
Summary of the difference between derived tables and subqueries
- derived tables are used in the FROM clause
- subqueries are used in the WHERE clause, but can also be used to select from one table and insert into another.
Read full article from difference between a derived table and a subquery
No comments:
Post a Comment