Generate a tree from a self-referential database table