graph

mail@pastecode.io avatar
unknown
sql
24 days ago
354 B
3
Indexable
Never
CREATE TABLE graph (
   id int UNIQUE NOT NULL,
   parentId int NULL,
   node_level int NOT NULL
)

insert into graph (id, parentId, node_level) values 
(1, NULL, 0),
(2, 1, 1),
(3, 2, 2),
(4, 3, 3),
(5, 2, 2),
(6, 5, 3),
(7, 6, 4),
(8, 5, 3),
(9, 6, 4),
(10, 7, 5);

(select id from graph) except (select distinct parentId from graph);