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 ubica.id_pd=r.ubica AND r.cat=cat.id_c AND r.e=1 ORDER BY r.fecha1 DESC LIM' at line 1