ERROR: 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 'and f.id = fr.id_formulario and fr.id_usuario_resposta = u.id and u.id_empresa =' at line 1 | SELECT fr.*, DATE_FORMAT(data_resposta, '%d/%m/%Y %k:%i') as data_resposta_formated, f.titulo, f.tipo, f.alerta, f.minimo, f.maximo, u.*, e.nome as empresaNome FROM formulario_resposta fr, usuario u, formulario f, empresa e where fr.id = and f.id = fr.id_formulario and fr.id_usuario_resposta = u.id and u.id_empresa = e.id ORDER BY fr.data_resposta desc