Select parent and child from the same table
问题 I have a emp table, CREATE TABLE [dbo].[Emp]( [EmpId] [int] NULL, [EmpName] [nvarchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [ManagerId] [int] NULL ) ON [PRIMARY] Now, insert below values into the table Insert Into Emp Values(1,'A',0) Insert Into Emp Values(2,'B',1) Insert Into Emp Values(3,'C',2) Insert Into Emp Values(4,'D',2) Insert Into Emp Values(5,'E',4) Insert Into Emp Values(6,'F',4) Insert Into Emp Values(7,'G',4) Insert Into Emp Values(8,'H',6) Insert Into Emp Values(9,'I'