SELECT
n.NodeID
FROM
Node AS n
LEFT JOIN
Relationship AS r
ON
n.NodeID = r.NodeChild
WHERE
r.NodeChild IS NULL
SELECT
n.NodeID
FROM
Node AS n
LEFT JOIN
Relationship AS r
ON
n.NodeID = r.NodeChild
WHERE
r.NodeChild IS NULL