pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Dmitry Tkach <dmitry@openratings.com>
To: Dave Dribin <dave-ml@dribin.org>
Cc: pgsql-sql@postgresql.org
Subject: Re: One to many query question
Date: Wed, 30 Jul 2003 17:26:23 -0400
Message-ID: <3F2837FF.7020805@openratings.com> (raw)
In-Reply-To: <20030730193517.GB1383@neo.realtors.org>
References: <20030730193517.GB1383@neo.realtors.org>

Dave Dribin wrote:

>Hi, I'm having trouble with what I think should be an easy query.  For
>simplicity, I will use a CD database as an example.  Each CD may have
>multiple genres.  Here's some sample data:
>
>Artist                  Title                           Genres
>----------------------  ------------------------------  ----------------
>Miles Davis		Some Kind of Blue		Jazz
>Metallica		Ride the Lightning		Rock
>Chemical Brothers	Surrender			Electronic
>Radiohead		OK Computer			Rock, Electronic
>
>For simplicities sake, let's ignore normalization on artist and genre,
>and say the tables look like:
>
>CREATE TABLE cd (
>	id integer unique,
>	artist varchar(25),
>	title varchar(25)
>);
>
>CREATE TABLE cd_genres (
>	cd_id integer,
>	genre varchar(25)
>);
>
>How do I write a query to find all CDs that are NOT Rock? 
>
What about
 select * from cd where not exists (select 1 from cd_genres where cd_id 
= cd.id and genre='Rock')?

Dima





view thread (10+ messages)  latest in thread

Message-ID: <3F2837FF.7020805@openratings.com>
Permalink:  ../3F2837FF.7020805@openratings.com/
Also on:    postgresql.org/message-id/3F2837FF.7020805@openratings.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: dmitry@openratings.com, dave-ml@dribin.org
  Subject: Re: One to many query question
  In-Reply-To: <3F2837FF.7020805@openratings.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