Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id E578A633651 for ; Mon, 1 Feb 2010 10:52:51 -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 94714-03 for ; Mon, 1 Feb 2010 14:52:32 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f222.google.com (mail-ew0-f222.google.com [209.85.219.222]) by mail.postgresql.org (Postfix) with ESMTP id D5BFE6332A3 for ; Mon, 1 Feb 2010 10:52:40 -0400 (AST) Received: by ewy22 with SMTP id 22so368722ewy.34 for ; Mon, 01 Feb 2010 06:52:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=uaG14uqoV02ViQCec2yJgEmYwK1hmacVH9d3bvgwPV8=; b=Hi3Q51EMeFFB/UGCLP4lGGUFyG+BSfp+i+ziSehbKldj3aFBcWmYIkf8433/plkbSh dKBCDXp9NgBYG92SCwzLo2nFhcqtCAmyeaHDTfO7s0S6L5WRapichyO1HR7ZLfitypFn rEu0mzSarNXKxCrTirj2yv+FA1bjlwK+hYpik= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=hG6A7uEnZucxWrV4vpq87OkCAJIYhY1KSvjJZpc+JbgVQ6ZnxpGGSX9rPQ4pk8fuCf EHdjh+7oEoB1cce2+q/ZCwOnqXyHLZog9YlipT8zs2jLNG4cF3nMHnu0gMMaMNM5SACN xallZWsxQAV3HNC5I+vf35RzjMadUf6G1Aytk= Received: by 10.213.44.9 with SMTP id y9mr364560ebe.71.1265035958452; Mon, 01 Feb 2010 06:52:38 -0800 (PST) Received: from ?0.0.0.0? (5357DA75.cable.casema.nl [83.87.218.117]) by mx.google.com with ESMTPS id 13sm3688517ewy.5.2010.02.01.06.52.35 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 01 Feb 2010 06:52:36 -0800 (PST) Message-ID: <4B66EAB4.4020900@gmail.com> Date: Mon, 01 Feb 2010 15:52:36 +0100 From: Yeb Havinga User-Agent: Thunderbird 2.0.0.23 (Windows/20090812) MIME-Version: 1.0 To: pgsql-sql@postgresql.org Subject: Re: selecting rows tagged with "a" but not "b" References: <11366-1265031099-334353@sneakemail.com> <20100201141453.GA8857@tux> In-Reply-To: <20100201141453.GA8857@tux> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-0.74 tagged_above=-10 required=5 tests=BAYES_20=-0.74 X-Spam-Level: X-Archive-Number: 201002/15 X-Sequence-Number: 33614 Andreas Kretschmer wrote: > 8q5tmkyqry@sneakemail.com <8q5tmkyqry@sneakemail.com> wrote: > > >> 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? >> > > select a.* from article left join tags t on a.articleID=t.articleID where b.tag = 'a'; > select a.* from article left join tags t on a.articleID=t.articleID where t.tag = 'a' where not exists (select * from tags t2 where t2.articleID=a.articleID and t2.tag = 'b'); Yeb