select * from ( select pid,id,name,url,concat(id,":") idOrder from menu where pid=0 and status_id=0 union select pid,id,concat(" ",name),url,concat(pid,":",id ) from menu where status_id=0 and pid in ( select id from menu where pid=0 and status_id=0 ) ) t order by idOrder