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.id NOT IN (SELECT DISTINCT id_oferta FROM ' at line 12 sql:SELECT d.id, d.nombre, d.permalink FROM bookingfax.destinos d LEFT JOIN bookingfax.ofertas_destinos od ON d.id = od.id_destino LEFT JOIN bookingfax.ofertas o ON o.id = od.id_oferta LEFT JOIN bookingfax.ofertas_categorias oc ON o.id = oc.id_oferta LEFT JOIN bookingfax.categorias c ON c.id = oc.id_categoria WHERE 1 AND c.id != 4 AND c.id != 7 AND o.pvp != "" AND o.multidistribucion=1 AND o.caducidad > curdate() AND d.id_padre = AND 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 = 50) GROUP BY d.nombre ORDER BY nombre ASC