The Apply operator involves one or two of the following two steps (depending on the type of APPLY): 1.A1 applies the right-table expression to the row of the left table. 2.A2: Add an external row. The apply operator applies the right-table expression to each row in the left input. The right table expression can reference a column in the left input, and for each row in the left table, the expression to the right input is evaluated once. This step matches each row on the left and the corresponding row from the right expression and merges the resulting result set to return the combined result. Cross apply and OUTER apply always contain step A1, and only out apply contains step A2. if the inner (right) table expression returns an empty set for an outer (left) row, cross APPLY does not return the outer (left) row. OUTER APPLY returns such rows, and null is used as a placeholder for the properties of the inner table expression. Example: The following query returns data from two tables in the category of cars:SELECT p.[d_id],P.[c_title],P.[e_title],P.[d_time],A.d_titleFrom [Dingtai]. [dbo]. [D_news_product] As PCross APPLY (SELECT c.d_id,D_title,C.d_timeFrom dbo. D_category as CWHERE c.d_id = P.class_one--order by c.d_id DESC ) as a GO------------------------Returns the result--------------------- * If you want to return data that does not contain classes for cars, use out APPLY: SELECT p.[d_id],P.[c_title],P.[e_title],P.[d_time],A.d_titleFrom [Dingtai]. [dbo]. [D_news_product] As P OUTER APPLY (SELECT c.d_id, D_title,C.d_timeFrom dbo. D_category as CWHERE c.d_id = P.class_one--order by c.d_id DESC ) as a GO-----------------------Results-----------------------------------------------------------------Knowledge of supplemental words------------------------------------------------------------
Apply |
English [?? Pla?] |
Beauty [?? Pla?] |
VT. |
Application; Coating Apply, use; Apply (medicine); |
vi. |
application, request, applicable; applicable, suitable for; devote oneself to; |
Examples I am continuing toapply for jobs I'm still looking for a job. Copyright? 2017Cheng. All rights Reserved.
Tsql2008 Query Performance Optimization Chapter---APPLY