[ACCEPTED]-Find leaf nodes in hierarchical tree-tree
Accepted answer
Your query didn't work because the sub-query 2 includes NULL
. The following slight modification 1 works for me:
SELECT * FROM `mytree` WHERE `id` NOT IN (
SELECT DISTINCT `parentid` FROM `mytree` WHERE `parentid` IS NOT NULL)
No clue why your query didn't work. Here's 2 the identical thing in left outer join syntax 1 - try it this way?
select a.*
from mytree a left outer join
mytree b on a.id = b.parentid
where b.parentid is null
SELECT * FROM mytree AS t1
LEFT JOIN mytree AS t2 ON t1.id=t2.parentid
WHERE t2.parentid IS NULL
0
Select * from mytree where id not in (Select distinct parentid from mytree where parentid is not null)
http://archives.postgresql.org/pgsql-sql/2005-10/msg00228.php
0
select *
from `mytree `
where not exists (select *
from `mytree ` as `nodes`
where `categories`.`id` = `nodes`.`parent`)
0
Source:
stackoverflow.com
More Related questions
Cookie Warning
We use cookies to improve the performance of the site. By staying on our site, you agree to the terms of use of cookies.