一个或多个派生表,这些派生表是 FROM 子句中的 SELECT 语句,以别名或用户指定的名称来引用这些派生表。FROM 子句中 SELECT 语句的结果集构成了外层 SELECT 语句所用的表。例如,下面的 SELECT 语句使用派生表查找是否有哪家书店备有 pubs 数据库中所有种类的书籍:
SELECT ST.stor_id, ST.stor_name
FROM stores AS ST,
(SELECT stor_id, COUNT(DISTINCT title_id) AS title_count
FROM sales
GROUP BY stor_id
) AS SA
WHERE ST.stor_id = SA.stor_id
AND SA.title_count = (SELECT COUNT(*) FROM titles)