| Welcome to WebmasterWorld Guest from 126.96.36.199 |
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
|Become a Pro Member|
|[mySql] Retrieving columns without children|
| 4:02 pm on May 19, 2011 (gmt 0)|
I am storing a tree in a mySql DB. Essentially I have 2 colums: id and parentId
1 0 //root
Is there an efficient query to get only those rows that have no children (in this case row with ids 4 and 5)
| 8:16 am on May 20, 2011 (gmt 0)|
SELECT distinct t1.id FROM
clouds AS t1 LEFT JOIN clouds as t2
ON t1.id <> t2.parent
where clouds is the name of the table
but it returns all the rows... On the other way:
SELECT distinct t1.id FROM clouds AS t1 LEFT JOIN clouds as t2 ON t1.id = t2.parent
Returns the rows that are not leaves...
| 11:36 pm on May 23, 2011 (gmt 0)|
LEFT JOIN the alias where IS NULL.
All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved