开发者

Find parent node?

There are two tables one with node names and another with connection details(child, parent) between the n开发者_运维问答odes find the node which has no parent i.e, root node. Using SQL query.


Here is a way to do this with a subquery:

SELECT *
FROM nodes
WHERE node_id NOT IN
(SELECT child_id FROM connectionTable)


I'd go for NOT EXISTS rather than NOT IN, as NOT IN can get slow.

SELECT *
    FROM nodes
    WHERE NOT EXISTS (SELECT *
                          FROM connectionTable
                          WHERE connectionTable.child_id = nodes.node_id)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜