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

From: "Milen A(dot) Radev" <milen(at)radev(dot)net>
To:
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: selecting rows tagged with "a" but not "b"
Date: 2010-02-01 13:56:05
Message-ID: 4B66DD75.5010506@radev.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

8q5tmkyqry(at)sneakemail(dot)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:
>
> <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?

Replace "SUBSTRACT" with "EXCEPT"
(http://www.postgresql.org/docs/current/static/sql-select.html#SQL-EXCEPT)

--
Milen A. Radev

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Andreas Kretschmer 2010-02-01 14:14:53 Re: selecting rows tagged with "a" but not "b"
Previous Message Andreas Gaab 2010-02-01 13:50:44 Re: selecting rows tagged with "a" but not "b"