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