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 p.lft' at line 1SELECT p.id, p.nombre, p.slug, p.venta_web FROM menuweb n, menuweb p WHERE n.lft BETWEEN p.lft AND p.rgt AND n.id = ORDER BY p.lft;