recursive query herarchical data sql server

Solutions on MaxInterview for recursive query herarchical data sql server by the best coders in the world

showing results for - "recursive query herarchical data sql server"
Colin
13 Aug 2018
1WITH cte_org AS (
2    SELECT       
3        staff_id, 
4        first_name,
5        manager_id
6        
7    FROM       
8        sales.staffs
9    WHERE manager_id IS NULL
10    UNION ALL
11    SELECT 
12        e.staff_id, 
13        e.first_name,
14        e.manager_id
15    FROM 
16        sales.staffs e
17        INNER JOIN cte_org o 
18            ON o.staff_id = e.manager_id
19)
20SELECT * FROM cte_org;
21Code language: SQL (Structured Query Language) (sql)
similar questions