Re: Matching several rows - Mailing list pgsql-sql

From Volkan YAZICI
Subject Re: Matching several rows
Date
Msg-id 20060118115517.GA578@alamut
Whole thread Raw
In response to Matching several rows  (Ivan Steganov <istegan6@gmail.com>)
Responses Re: Matching several rows  (Michael Glaesemann <grzm@myrealbox.com>)
List pgsql-sql
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.


pgsql-sql by date:

Previous
From: Michael Glaesemann
Date:
Subject: Re: Still struggling with history tables
Next
From: Michael Glaesemann
Date:
Subject: Re: Matching several rows