sql >> Base de Datos >  >> RDS >> Mysql

Seleccionar contra subconjuntos de una lista en MySQL

Si pretende que su filtro está en una tabla:

select * 
from product p
where not exists (
    select 1
    from attributes a
    where a.product_id = p.product_id
    and not exists(
        select 1
        from filter f
        where f.id_attribute = a.id_attribute))

Si estaba en una consulta construida:

select * 
from product p
where not exists (
    select 1
    from attributes a
    where a.product_id = p.product_id
    and attribute_id not in (<list>))

Esto está fuera de mi cabeza, por lo que puede haber errores tipográficos.