Listing all Parents of an items in a hierarchy table as delimitted string SQL
问题 I have an SQL table like this ID Name ParentID ------------------------------ 1 Alex 0 2 John 0 3 Don 1 4 Philip 2 5 Shiva 2 6 San 3 7 Antony 6 8 Mathew 2 9 Cyril 8 10 Johan 9 ------------------------- Am looking for an out put like this if I pass the ID 7,10 The out put table will be ID Name Relation ------------------------------------ 7 Antony Alex->Don->San->Antony 10 Johan John->Mathew->Cyril->Johan How can I achieve that using CTE 回答1: This seems to do the trick. The key is to realise