I have following table in SQL server
(id,name,parentId)
(1,nilesh,NULL)
(2,nikhil,1)
(3,nitin ,2)
(4,Ruchi,3)
(5,xx,NULL)
(6,YY,5)
(7,ZZ,6)
I want to find the last child in each group
result: (4,Ruchi,3),(7,ZZ,6)
How to do it?
Checking: