You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order by catname' at line 3select c1.*,catname_hu as catname, caturl_hu, (select count(*) from cat csub where csub.parid = c1.cid) AS catct,(select count(*) from comp2cat cc left join companies c on cc.compid = c.compid where cc.cid = c1.cid and c.activ = '1' and cc.sponsored = '0') AS compct from cat c1 where c1.parid = order by catname