Re: SQL Question - Mailing list pgsql-novice

From Mo Holkar
Subject Re: SQL Question
Date
Msg-id 5.1.0.14.2.20011111120039.009fda50@pop.ntlworld.com
Whole thread Raw
In response to SQL Question  (Brian <Brrrian@Excite.com>)
Responses XML & Postgresql
List pgsql-novice
At 18:26 10/11/01, you wrote:
>A SQL Question...
>
>Bear with me... I'm kinda new here.
>
>I am trying to query table1, selecting records that do NOT have a relation
>in a subset from table3 that is related to table2.
>
>
>Example:
>
>table1(Trick table)
>  1_id,trickName,trickDescription
>
>table2(Magician table)
>  2_id,lastName,firstName
>
>table3(Trick-Magician-Knows table)
>  2_id,1_id
>
>if I choose some magician I want a list of tricks he/she DOES-NOT know.


Interesting question! I'm no SQL expert either... I would use something like:

SELECT one_id FROM table1 EXCEPT SELECT one_id FROM table3 WHERE
table3.two_id = table2.two_id AND table2.lastName = '<name of magician to
test for>';

which does generate the correct results, but there are probably more
elegant ways of doing it.

best,

Mo



Mo Holkar
Digital Mind Games -- log on to take over
mo.holkar@digitalmindgames.com
http://www.digitalmindgames.com


pgsql-novice by date:

Previous
From: "Brett W. McCoy"
Date:
Subject: Re: Sending query to a file
Next
From: Henk
Date:
Subject: config problems