title: How do you calculate the depth of a tree with a sql statement?
body: <p>I don't quite get how recursive queries work and how to solve this problem. We were given the table on the left and the structure looks like the tree on the right:</p>
  
  <pre><code>ID | Parent                        1
  1     null                        / \
  2     1                          2   3
  3     1                               \
  4     3                                4
  5     4                               / \
  6     4                              5   6   
  7     6                                   \ 
                                             7 
  </code></pre>
  
  <p>I know how to get all the parent nodes of every node... but I don't get how you find the max depth of the tree. Meaning I have to find out how many levels this tree has. We aren't given any more information</p>
  
  <p>I would be super grateful if you could give me a solution for mysql, but any sql statement will help me figuring this out</p>
  
  <p>Thanks in advance!</p>