Join the same table to itself

I have a table with id, parent_id that is multiple layers deep. This code in mysql shows what I need. Can’t get it to work in SC.

SELECT a.id, a.parent_id, b.id, b.parent_id FROM notebook_pages a, notebook_pages b WHERE b.parent_id = a.id

How can I make that work in SC?

I have tried the query builder with alias for the table but it only lets me select the table once.

you have to use JOINS between the 2 tables. can be done with sql builder