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 ') as foo on foo.id_voce = v.id_voce order by v.sort' at line 1