Depending on the platform, there are different SQL operators available to handle recursive parent/child connections for nested PK/FK relationships in a single table. Oracle uses a CONNECT BY clause while Postgres offers a WITH RECURSIVE/UNION ALL clause. Note the below Postgres query uses a CTE (common table expression) to add the Level column using AS. Once the Level column is established further queries allow creating a path of every tree vs. jus the results below that show where the children exist in the tree.