This query joins the table to itself based on the parent_id and displays all fields from the node and its parent node. Because a left join is used, the results will include all nodes with their parents, including the root nodes.
Because the same table is referenced twice in the same query, an alias must be used to distinguish between the two tables. The syntax "nodes as parent" creates the alias "parent".
SELECT nodes.*, parent.*
FROM nodes
LEFT JOIN nodes AS parent
ON nodes.parent_id = parent.id
To find nodes where the parent type is not equal to "RND" as in your query above, you would need to add the below where clause to the query.
WHERE parent.type != 'RND' OR parent.type IS NULL
The important point here which I believe you are missing in your above query is the way that NULL values and comparison operators work together. The result of NULL with most comparison operators and any other value always comes out as false. This is why the second condition is needed in the where clause above. The "IS" keyword is a special keyword which can be used to check for null values.