Answer the question
In order to leave comments, you need to log in
How to check multiple conditions in having when using array_agg?
the sets table also has a group column, which can be 1 or 2.
How to rewrite the query to take into account not only the fact that the found rows contain the ARRAY[1,2,3] array, but also that all of them belong to only one of the groups (1 or 2)
SELECT country_id FROM countries
WHERE EXISTS
(SELECT 1 FROM sets
WHERE (sets.country_id = countries.country_id AND sets.is_used = true)
HAVING(array_agg(sets.city_id) @> ARRAY[1, 2, 3]))
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question