GrandParent = Category.alias() .join(Parent, on=(Category.parent == Parent.id)) .order_by(Category.name))