pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Gaab <A.Gaab@scanlab.de>
To: '8q5tmkyqry@sneakemail.com' <8q5tmkyqry@sneakemail.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: selecting rows tagged with "a" but not "b"
Date: Mon, 1 Feb 2010 14:50:44 +0100
Message-ID: <48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de> (raw)
In-Reply-To: <11366-1265031099-334353@sneakemail.com>
References: <11366-1265031099-334353@sneakemail.com>

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@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] Im Auftrag von 8q5tmkyqry@sneakemail.com
Gesendet: Montag, 1. Februar 2010 14:32
An: pgsql-sql@postgresql.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@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql


view thread (6+ messages)  latest in thread

Message-ID: <48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de>
Permalink:  ../48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de/
Also on:    postgresql.org/message-id/48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de

 · 

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: A.Gaab@scanlab.de, 8q5tmkyqry@sneakemail.com
  Subject: Re: selecting rows tagged with "a" but not "b"
  In-Reply-To: <48DA836F3865C54B8FBF424A3B775AF6F8ED2A6D@Exchange-Server.scanlab-intern.de>

* 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