In this tutorial We have share how to get all parent categories from child category with a single query in MYSQL
I do this:
$childCategoryID = 55
SELECT c.*
FROM (
SELECT
@r AS _id,
(SELECT @r := parent_id FROM category WHERE id = _id) AS parent_id,
@l := @l + 1 AS level
[...]