MySQL i: (1064) 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 o.pvp != "" AND o.caducidad >= curdate() GROUP BY o.titulo ' at line 16 sql:SELECT date_format(o.primera_salida,"%d/%m/%Y") primera, date_format(o.ultima_salida,"%d/%m/%Y") ultima, o.titulo titulo, o.url, d.nombre destino, m.nombre proveedor, o.id id_oferta, o.pvp, o.permalink FROM bookingfax.ofertas o INNER JOIN bookingfax.ofertas_destinos od ON o.id = od.id_oferta INNER JOIN bookingfax.destinos d ON od.id_destino = d.id INNER JOIN bookingfax.ofertas_categorias oc ON oc.id_oferta = o.id INNER JOIN bookingfax.marcas m ON o.marca = m.id WHERE o.id NOT IN (SELECT DISTINCT id_oferta FROM bookingfax.ofertas_categorias WHERE id_categoria = 4 OR id_categoria = 7) AND o.marca IN (SELECT id_proveedor FROM bookingfax.bookingfax_proveedores_por_grupo WHERE id_grupo = 3) AND o.multidistribucion=1 AND d.id = AND o.pvp != "" AND o.caducidad >= curdate() GROUP BY o.titulo ORDER BY primera, proveedor