You probably need to do this using recursion, for example something like this stored procedure...
DELIMITER //
CREATE PROCEDURE PrintHierachy
(IN parentId DECIMAL(19, 0), IN indent VARCHAR(1000))
BEGIN
DECLARE itemName VARCHAR(255);
DECLARE childId DECIMAL(19, 0);
DECLARE csr CURSOR FOR
SELECT id
FROM MY_TABLE
WHERE parentId = parentId
ORDER BY NAME;
IF parentId > 0 THEN
SELECT itemName INTO FROM MY_TABLE WHERE id=parentId;
% Print it
SELECT concat(indent, itemName);
END IF;
OPEN csr;
child_loop: LOOP
FETCH csr INTO childId;
IF done THEN
LEAVE child_loop;
END IF;
% Recurse
CALL PrintHierachy(concat(' '), childId);
END LOOP;
CLOSE csr;
END;
This assumes that the top level has parent Ids of "0".
e.g. CALL PrintHierachy('', 0)
(I've not used stored procs in MySQL before, but have in other DBMSs so forgive me if this does not compile!)