From: | Mo Holkar <pgsql(at)digitalmindgames(dot)com> |
---|---|
To: | pgsql-novice(at)postgresql(dot)org |
Subject: | Re: SQL Question |
Date: | 2001-11-11 13:18:14 |
Message-ID: | 5.1.0.14.2.20011111120039.009fda50@pop.ntlworld.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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(dot)holkar(at)digitalmindgames(dot)com
http://www.digitalmindgames.com
From | Date | Subject | |
---|---|---|---|
Next Message | Henk Schets | 2001-11-12 09:12:24 | configuration problems |
Previous Message | Brett W. McCoy | 2001-11-10 21:32:16 | Re: Sending query to a file |