Quote

there is a table id_m (int), id_t (int) which provides a many-to-many relationship. You need to select id_m whose id_t completely overlap with the ones specified in the request. eg:

id_m | id_t ------------- 1 | 1 1 | 2 3 | 1 

id_m = 1 should be returned in response when id_t = {1,2} is requested (and id_m = 3 does not get, because it does not have id_t = 2) How can this be done? at first thought you can make the table id_m | array (id_t) as t and then compare the two arrays - t and {1,2} But the question here is how to make a request that would assemble the corresponding id_t into an array. or maybe some more elegant way

1 answer 1

 select id_m from some_m2m group by id_m having array_agg(id_t) = '{1, 2}';