I'm trying to get the top parent id from category table:
+-------------+----------------------+--------+
| category_id | name | parent |
+-------------+----------------------+--------+
| 1 | ELECTRONICS | NULL |
| 2 | TELEVISIONS | 1 |
| 3 | TUBE | 2 |
| 4 | LCD | 2 |
| 5 | PLASMA | 2 |
| 6 | PORTABLE ELECTRONICS | 1 |
| 7 | MP3 PLAYERS | 6 |
| 8 | FLASH | 7 |
| 9 | CD PLAYERS | 6 |
| 10 | 2 WAY RADIOS | 6 |
+-------------+----------------------+--------+
There can be a lot of subcategories and my question is how to get the top parent of whatever the subcategory is?
For example, in database subcategory node can look like this:
parent>>subcategory>>subsubcategory>>subsubsubcategory
and another node can look like this:
parent>>subcategory
So if I query for top parent of subcategory with id=6, I get ELECTRONICS, etc.
How to get the top parent id with mysql? I hope that, this is fully understandable.