Error SQL You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'AND a.activo ORDER BY a.fecha DESC' at line 1 SELECT id_articulo, a.titulo FROM consulta_articulos c JOIN articulo a ON c.id_articulo = a.id WHERE c.id_subcategoria = AND a.activo ORDER BY a.fecha DESC