My table structure:
--------------------------
|Categories |
--------------------------
|id |parent_id|title |
--------------------------
|1 |null |t1 |
--------------------------
|2 |1 |t2 |
--------------------------
|3 |1 |t3 |
--------------------------
|4 |2 |t4 |
--------------------------
|5 |4 |t5 |
--------------------------
|6 |null |t6 |
--------------------------
I need to find out how many items are between a given item/category and its root item/category including the specified item and the root item.
For example in this table title=t5
would have a count of 4 (t1
->t2
->t4
->t5
).
MySQL Version: 5.6.21