X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 0FE52D1C7F1 for ; Wed, 30 Jul 2003 20:11:38 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 84632-08 for ; Wed, 30 Jul 2003 17:10:36 -0300 (ADT) Received: from paperboy.corp.tmtrading.com (mail.intmt.com [205.161.220.3]) by svr1.postgresql.org (Postfix) with ESMTP id 53A98D1C4EB for ; Wed, 30 Jul 2003 17:11:36 -0300 (ADT) Received: from [205.161.220.44] (unknown [205.161.220.44]) by paperboy.corp.tmtrading.com (Postfix) with ESMTP id 73E0A12BB08; Wed, 30 Jul 2003 13:11:25 -0700 (MST) Subject: Re: One to many query question From: Eric Clark To: Dave Dribin Cc: "pgsql-sql@postgresql.org" In-Reply-To: <20030730193517.GB1383@neo.realtors.org> References: <20030730193517.GB1383@neo.realtors.org> Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 (1.0.8-10) Date: 30 Jul 2003 13:11:35 -0700 Message-Id: <1059595896.12276.16.camel@eric> Mime-Version: 1.0 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/469 X-Sequence-Number: 14583 On Wed, 2003-07-30 at 12:35, Dave Dribin wrote: > CREATE TABLE cd ( > id integer unique, > artist varchar(25), > title varchar(25) > ); > > CREATE TABLE cd_genres ( > cd_id integer, > genre varchar(25) > ); I think you've got this backwards. There is no advantage in the above table's over simply having a genre varchar(25) in the cd table. You really want: CREATE TABLE genre ( genre_id serial, genre varchar(25) ); CREATE TABLE cd ( cd_id integer unique, artist varchar(25), title varchar(25), genre_id varchar(25) references genre (genre_id) ); > How do I write a query to find all CDs that are NOT Rock? A co-worker > showed me the following query: Now the query is simple: SELECT cd.*, genre.genre FROM cd, genre WHERE cd.genre_id = genre.genre_id AND genre.genre != 'Rock'; Hope that helps, Eric