X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 1AAEAD7CB0 for ; Wed, 7 Sep 2005 18:54:30 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 59587-06 for ; Wed, 7 Sep 2005 21:54:24 +0000 (GMT) Received: from hotmail.com (bay101-f10.bay101.hotmail.com [64.4.56.20]) by svr1.postgresql.org (Postfix) with ESMTP id 7C718D7B95 for ; Wed, 7 Sep 2005 18:54:24 -0300 (ADT) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Wed, 7 Sep 2005 14:54:25 -0700 Message-ID: Received: from 64.4.56.200 by by101fd.bay101.hotmail.msn.com with HTTP; Wed, 07 Sep 2005 21:54:24 GMT X-Originating-IP: [64.4.56.200] X-Originating-Email: [x_download@hotmail.com] X-Sender: x_download@hotmail.com In-Reply-To: <20050906144541.GA30161@wolff.to> From: "DownLoad X" To: bruno@wolff.to Cc: pgsql-sql@postgresql.org Subject: Re: Searching for results with an unknown amount of data Date: Wed, 07 Sep 2005 22:54:24 +0100 Mime-Version: 1.0 Content-Type: text/plain; format=flowed X-OriginalArrivalTime: 07 Sep 2005 21:54:25.0165 (UTC) FILETIME=[B64B6BD0:01C5B3F6] X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=2.915 required=5 tests=[AWL=-0.666, DNS_FROM_RFC_ABUSE=0.374, DNS_FROM_RFC_POST=1.376, MSGID_FROM_MTA_HEADER=0, RCVD_IN_BL_SPAMCOP_NET=1.832] X-Spam-Level: ** X-Archive-Number: 200509/80 X-Sequence-Number: 22627 > > Now, I want to find all objects that have at most properties 1,2,3, say >(so > > something with (1,2) is okay, as is (1,2,3)). I can't see a way to do >this > > -- can anyone help? > >It sounds like you are trying to find all objects that do not have any >properties outside of a specific list. One way to get that list is: That's exactly right. > >SELECT a_id > FROM a > WHERE > NOT EXISTS > (SELECT 1 > FROM b > WHERE > b.a_id = a.a_id > AND > b.property NOT IN (1, 2, 3) > ) >; Yupp, this appears to do it! The 'double negation' is very clever. Thanks a lot, DL