From the provided sample data, max level might be two.
If this guess was right,
the following query might be an answer...
Code:
SELECT c.*
FROM categories AS c
INNER JOIN
categories AS p
ON p.catid = COALESCE( NULLIF(c.parentid , 0) , c.catid )
ORDER BY
p.catname
, c.level
, c.catname
;
If the max level was not clear,
loop or recursive query might be neccesary to find the catname of the level 1 categories.