How to make this nested query :-
You just need to add to the where statement to filter for those that are the primary level

SELECT * 
FROM foo AS f1
WHERE id = parent_id
AND id IN (
  SELECT f2.parent_id
  FROM foo AS f2
  WHERE f1.id = f2.parent_id
    AND f2.id != f2.parent_id
);