X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 58F049DC9C0 for ; Wed, 18 Jan 2006 07:59:52 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 26754-04 for ; Wed, 18 Jan 2006 07:59:52 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from fep01.ttnet.net.tr (mail.ttnet.net.tr [212.175.13.129]) by postgresql.org (Postfix) with ESMTP id 7F96B9DC814 for ; Wed, 18 Jan 2006 07:57:56 -0400 (AST) Received: from alamut ([85.102.233.174]) by fep01.ttnet.net.tr with ESMTP id <20060118115347.KXLY1401.fep01.ttnet.net.tr@alamut>; Wed, 18 Jan 2006 13:53:47 +0200 Date: Wed, 18 Jan 2006 13:55:17 +0200 From: Volkan YAZICI To: Ivan Steganov Cc: pgsql-sql@postgresql.org Subject: Re: Matching several rows Message-ID: <20060118115517.GA578@alamut> References: <3578f52e0601172043s64561353i689350a1c5d4debb@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3578f52e0601172043s64561353i689350a1c5d4debb@mail.gmail.com> User-Agent: Mutt/1.4.2.1i X-NAI-Spam-Rules: 0 Rules triggered X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=1.985 required=5 tests=[AWL=-0.813, DNS_FROM_RFC_ABUSE=0.479, DNS_FROM_RFC_POST=1.44, DNS_FROM_RFC_WHOIS=0.879, UPPERCASE_25_50=0] X-Spam-Score: 1.985 X-Spam-Level: * X-Archive-Number: 200601/116 X-Sequence-Number: 23905 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.