Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 9CD6C632EA4 for ; Mon, 1 Feb 2010 09:56:19 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 83615-08 for ; Mon, 1 Feb 2010 13:56:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from rt.zoiper.com (gw-sf.securax.net [89.190.196.114]) by mail.postgresql.org (Postfix) with ESMTP id 41D17632420 for ; Mon, 1 Feb 2010 09:56:07 -0400 (AST) Received: (qmail 19696 invoked by uid 89); 1 Feb 2010 13:56:04 -0000 Received: from unknown (HELO ?10.2.2.172?) (milen@securax.org@10.2.2.172) by mail.support.bg with ESMTPA; 1 Feb 2010 13:56:04 -0000 Message-ID: <4B66DD75.5010506@radev.net> Date: Mon, 01 Feb 2010 15:56:05 +0200 From: "Milen A. Radev" User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 CC: pgsql-sql@postgresql.org Subject: Re: selecting rows tagged with "a" but not "b" References: <11366-1265031099-334353@sneakemail.com> In-Reply-To: <11366-1265031099-334353@sneakemail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.559 tagged_above=-10 required=5 tests=AWL=-0.252, BAYES_00=-2.599, MISSING_HEADERS=1.292 X-Spam-Level: X-Archive-Number: 201002/11 X-Sequence-Number: 33610 8q5tmkyqry@sneakemail.com написа: > Hi, > > I have a two tables: > > article > articleID, name, content > > tags > articleID, tag > > I want to find all articles that are tagged with "a" but not "b" > > how do I do this? > > what I'd like to do is: > > > select articleID from tags where tag="a" > SUBTRACT > select articleID from tags where tab="b" > > > how do I do this in real SQL? Replace "SUBSTRACT" with "EXCEPT" (http://www.postgresql.org/docs/current/static/sql-select.html#SQL-EXCEPT). -- Milen A. Radev