Select top-most folder in a hierarchy by given criteria in MySQL
I think you want this. All the results from users table except those that have a parent in users:

SELECT u.user, u.child
FROM users AS u 
WHERE NOT EXISTS
      ( SELECT 1 
        FROM users AS u2
             JOIN folder AS f 
             ON f.parent = u2.child
        WHERE f.child = u.child
          AND f.dist &gt; 0         -- this could be: AND f.parent &lt;&gt; f.child
          AND u2.user = u.user
      ) ;