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 '\'' at line 1 SQL:SELECT * FROM risultati_attesi as a join (select id_aep from aep_table where risultati_attesi=1) as b on a.id_aep=b.id_aep where a.id_ada=\'