pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Volkan YAZICI <yazicivo@ttnet.net.tr>
To: Ivan Steganov <istegan6@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Matching several rows
Date: Wed, 18 Jan 2006 13:55:17 +0200
Message-ID: <20060118115517.GA578@alamut> (raw)
In-Reply-To: <3578f52e0601172043s64561353i689350a1c5d4debb@mail.gmail.com>
References: <3578f52e0601172043s64561353i689350a1c5d4debb@mail.gmail.com>

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.



view thread (9+ messages)  latest in thread

Message-ID: <20060118115517.GA578@alamut>
Permalink:  ../20060118115517.GA578@alamut/
Also on:    postgresql.org/message-id/20060118115517.GA578@alamut

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: yazicivo@ttnet.net.tr, istegan6@gmail.com
  Subject: Re: Matching several rows
  In-Reply-To: <20060118115517.GA578@alamut>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox