Re: Matching several rows

From: Volkan YAZICI <yazicivo(at)ttnet(dot)net(dot)tr>
To: Ivan Steganov <istegan6(at)gmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Matching several rows
Date: 2006-01-18 11:55:17
Message-ID: 20060118115517.GA578@alamut
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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.

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Daryl Richter 2006-01-18 12:32:53 Re: bug with if ... then ... clause in views
Previous Message Achilleus Mantzios 2006-01-18 10:23:28 Re: Still struggling with history tables