-
Notifications
You must be signed in to change notification settings - Fork 22
子查询:相关子查询、无关子查询
曾璐 edited this page Dec 28, 2016
·
1 revision
内部查询未引用外部查询的表->整个查询的过程为子查询只执行一次,然后交给外部查询 eg.
SELECT P.ProductID, P.Name, P.ProductNumber, M.Name AS ProductModelName
FROM Production.Product AS P
INNER JOIN
(SELECT Name, ProductModelID
FROM Production.ProductModel) AS M
ON P.ProductModelID = M.ProductModelID
内部查询引用外部查询的表->子查询的执行的次数依赖于外部查询,外部查询每执行一行,子查询执行一次
eg.
SELECT [FirstName],[MiddleName],[LastName]
FROM [AdventureWorks].[Person].[Contact] c
WHERE EXISTS
(SELECT *
FROM [AdventureWorks].[HumanResources].[Employee] e
WHERE c.ContactID=e.ContactID AND e.SickLeaveHours>68)
内部查询引用了外部查询c表
参考:http://www.cnblogs.com/CareySon/archive/2011/07/18/2109406.html