Hi,
On Jan 18 05:43, Ivan Steganov wrote:
> ID RIGHT
> ---------------------
> 20 1
> 20 2
> 20 5
> 20 10
> 30 2
> 30 10
>
> Now I need to find out which IDs have, say rights 2 AND 5 AND 10.
SELECT t.id
FROM (SELECT id, sum(1) AS s FROM id_n_rights WHERE rights = ANY(ARRAY[2,5,10]) GROUP BY id) AS t
WHERE t.s = 3; -- 3 = length(ARRAY[2,5,10])
HTH.
Regards.