| 1. |
How Can We Rewrite Sub-queries Into Simple Select Statements Or With Joins? |
|
Answer» we can write using Common Table Expression (CTE). A Common Table Expression (CTE) is an expression that can be thought of as a temporary result set which is defined within the execution of a single SQL statemnt. A CTE is similar to a DERIVED table in that it is not stored as an object and LASTS only for the duration of the query. E.g. USE AdventureWorks GO WITH EmployeeDepartment_CTE AS(SELECT EmployeeID,DepartmentID, ShiftID FROM HUMANRESOURCES.Employee Department History) SELECT ECTE.EmployeeId, ED.Department ID, ed.Name, ecte.ShiftID FROM HumanResources. Department ed INNER JOIN EmployeeDepartment_CTE ecte ON ecte. Department ID = ed.Department ID GOwe can write using Common Table Expression (CTE). A Common Table Expression (CTE) is an expression that can be thought of as a temporary result set which is defined within the execution of a single SQL statemnt. A CTE is similar to a derived table in that it is not stored as an object and lasts only for the duration of the query. E.g. |
|