mysql - Need to query a self referencing table to find all items that are NOT the parent of any item -


like title says, need query self referencing table find items not parent of item.

my table attached image link:

here schema:

 create table if not exists `recursivebom`.`level` (    `level` int not null,    primary key (`level`))  engine = innodb; 

-- table recursivebom.item


 create table if not exists `recursivebom`.`item` (    `itemnumber` int not null,    `quantity` decimal null,    `cost` decimal null,    `parentitem` int null,    `level` int not null,    primary key (`itemnumber`, `level`),    index `fk_item_item1_idx` (`parentitem` asc),    index `fk_item_level1_idx` (`level` asc),    constraint `fk_item_item1`      foreign key (`parentitem`)      references `recursivebom`.`item` (`itemnumber`)      on delete no action      on update no action,    constraint `fk_item_level1`     foreign key (`level`)      references `recursivebom`.`level` (`level`)      on delete no action      on update no action)  engine = innodb; 

how this?

select *    item  itemnumber not in (select parentitem item) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -