I am trying to understand the concepts of using CTE in my SQL code. I have gone through a number of online posts explaining the concept but I cannot grasp how it iterates to pre
It's all about recursive step: firstly, root is used to proceed first step of recursion, so:
SELECT EmployeeID, ContactID, LoginID, ManagerID, Title, BirthDate
FROM HumanResources.Employee
WHERE ManagerID IS NULL
This provides first set of records.
Second set of records will be queried based on first set (anchor), so it will query all employees, which have manager in first set.
Second step of recursion will be based on second result set, not the anchor.
Third step will be based on third result set, etc.