Retrieve hierarchy from a table like this

Printable View