SELECT d.* FROM c_documentos AS d JOIN c_cursos_documentos AS cd ON d.id=cd.id_documento JOIN c_cursos c ON cd.id_curso=c.id WHERE c.id= 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