* Michelle de Beer > I believe this question is solved by a join, but I > haven't really got a hang of it. > > My table: > -------------------------------------- > | uid | rootid | parentid | name | > -------------------------------------- > | 1 | 0 | 0 | name1 | > | 2 | 1 | 1 | name2 | > | 3 | 1 | 2 | name3 | > | 4 | 1 | 3 | name4 | > | 5 | 1 | 2 | name5 | > ... > > How do I get this (WHERE uid=5): > ------------------------------------------ > | rootid_name | parentid_name | name | > ------------------------------------------ > | name1 | name2 | name5 | > ------------------------------------------
Try two self joins: SELECT r.name rootid_name,p.name parentid_name, name FROM tablename t LEFT JOIN tablename r ON r.uid = t.rootid LEFT JOIN tablename p ON p.uid = t.parentid WHERE t.uid = 5; -- Roger sql --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php