Skip to main content
Admissions guidance, study banks, and career tools — get started on Shalyam

Depth of Each Node

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.

Rewards · v2.1

Get Exclusive Insights with Every Issue

Join Shalyam Newsletter

Stay ahead in education, research, and innovation—straight to your inbox.