SELECT * FROM testTree;
SELECT
tbl1.id,
tbl1.name,
tbl1.pid
FROM
testTree tbl1
WHERE
EXISTS (
SELECT
tbl2.pid
FROM
testTree tbl2,
(
SELECT
tbl4.pid
FROM
testTree tbl4
WHERE
EXISTS (
SELECT
tbl5.pid
FROM
testTree tbl5
WHERE
tbl4.id = tbl5.pid
)
) tbl3
WHERE
tbl2.id = tbl3.pid
);