pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Yeb Havinga <yebhavinga@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: selecting rows tagged with "a" but not "b"
Date: Mon, 01 Feb 2010 15:52:36 +0100
Message-ID: <4B66EAB4.4020900@gmail.com> (raw)
In-Reply-To: <20100201141453.GA8857@tux>
References: <11366-1265031099-334353@sneakemail.com>
	<20100201141453.GA8857@tux>

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





view thread (6+ messages)

Message-ID: <4B66EAB4.4020900@gmail.com>
Permalink:  ../4B66EAB4.4020900@gmail.com/
Also on:    postgresql.org/message-id/4B66EAB4.4020900@gmail.com

 · 

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: yebhavinga@gmail.com
  Subject: Re: selecting rows tagged with "a" but not "b"
  In-Reply-To: <4B66EAB4.4020900@gmail.com>

* 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