WHERE NOT EXISTS (SELECT 1 FROM ManyToManyTable INNER JOIN ChildTable ON ManyToManyTable.NoChildTable=ChildTable.Numero WHERE Master.Numero=ManyToManyTable.NoMaster AND ChildTable.Enabled <> 1 )>Here is an example, where I added Sergey's logic in it:
>SELECT Master.Numero >FROM (SELECT Master.Numero FROM Master >WHERE EXISTS (SELECT 1 FROM ManyToManyTable > INNER JOIN ChildTable ON ManyToManyTable.NoChildTable=ChildTable.Numero > WHERE Master.Numero=ManyToManyTable.NoMaster > HAVING COUNT(*)=SUM(CASE WHEN ChildTable.Enabled=1 THEN 1 ELSE 0 END)) >GROUP BY Master.Numero) Temp >INNER JOIN Master ON Temp.Numero=Master.Numero >