Hi, Given a simple tree structure represented in a table shown below:
group_id: int parent_group_id: int description: varchar I am trying to select all rows from a table where the group_id does not appear elsewhere as a parent_group_id, hence selecting only the leaf nodes. I have wrestled with the query below but cannot get it to perform as I expected. SELECT DISTINCT A.group_id, A.group_description FROM Product_Group A, Product_Group B WHERE B.parent_group_id != A.group_id ORDER BY A.group_description ASC I would normally perform this using a sub select but obviously using mySQL I must look elsewhere. I could implement using a temp table but would prefer a single query answer. I may have got recursive selects a bit twisted so anyone with superior SQL skill suggest where I am failing? Many Thanks, Andrew. --------------------------------------------------------------------- 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