The not-in clause expects a list of values. Thus, the following query will work:
SELECT * from campaigns WHERE id not in
(SELECT
e.id_campaign
FROM campaigns d
LEFT JOIN served e
ON d.id = e.id_campaign
WHERE
d.status = 'Active'
GROUP BY e.id_campaign
HAVING
COUNT(e.id) < d.frequency)
If you can tell us about the structure of the tables and what you want to choose, we can find the right query for you.
source
share