Re: selecting rows tagged with "a" but not "b"

From: Andreas Gaab <A(dot)Gaab(at)scanlab(dot)de>
To: "'8q5tmkyqry(at)sneakemail(dot)com'" <8q5tmkyqry(at)sneakemail(dot)com>, "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: selecting rows tagged with "a" but not "b"
Date: 2010-02-01 13:50:44
Message-ID: 48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi Darrell,

SELECT DISTINCT articleID FROM tags WHERE tag = "a"
EXCEPT
SELECT DISTINCT articleID FROM tags WHERE tag = "b";

Regards,

Andreas

-----Ursprüngliche Nachricht-----
Von: pgsql-sql-owner(at)postgresql(dot)org [mailto:pgsql-sql-owner(at)postgresql(dot)org] Im Auftrag von 8q5tmkyqry(at)sneakemail(dot)com
Gesendet: Montag, 1. Februar 2010 14:32
An: pgsql-sql(at)postgresql(dot)org
Betreff: [SQL] selecting rows tagged with "a" but not "b"

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:

<wishful thinking>
select articleID from tags where tag="a"
SUBTRACT
select articleID from tags where tab="b"
</wishful thinking>

how do I do this in real SQL?

thanks

Darrell

--
Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Milen A. Radev 2010-02-01 13:56:05 Re: selecting rows tagged with "a" but not "b"
Previous Message Oliveiros C, 2010-02-01 13:44:57 Re: selecting rows tagged with "a" but not "b"