Depth of Each Node
Medium
Hierarchical Data
Return every node's depth where the root has depth 0. Order by id.
Table schema
Tree(id INT PRIMARY KEY, p_id INT NULL)Sample data
id | p_id
1 | NULL
2 | 1
3 | 1
4 | 2
5 | 2
Discussion
No discussions yet.
Shalyam Support
Hi! Ask us anything — we'll reply on WhatsApp or Telegram within 24 hours.