Re: Help with a view

From: "Dmitri Bichko" <dbichko(at)aveopharma(dot)com>
To: "Leif B(dot) Kristensen" <leif(at)solumslekt(dot)org>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Help with a view
Date: 2005-09-22 19:10:42
Message-ID: F18A6F7CF1661F46920F2CF713122FED46CCAE@mail.aveo.aveopharma.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I don't understand how this is different:

SELECT person FROM principals
WHERE event IN (SELECT event FROM principals WHERE person = $p AND
tag_type = " .MARR. ")
AND person != $p
ORDER BY sort_date

Or without subselects:

SELECT p1.person
FROM principals p1
JOIN principals p2 USING(event)
WHERE p2 person = $p
AND p2.tag_type = " .MARR. "
AND p1.person != $p
ORDER BY sort_date

Am I being confused?

Dmitri

> -----Original Message-----
> From: pgsql-sql-owner(at)postgresql(dot)org
> [mailto:pgsql-sql-owner(at)postgresql(dot)org] On Behalf Of Leif B.
> Kristensen
> Sent: Thursday, September 22, 2005 2:12 PM
> To: pgsql-sql(at)postgresql(dot)org
> Subject: Re: [SQL] Help with a view
>
>
> On Thursday 22 September 2005 20:03, Dmitri Bichko wrote:
>
> > SELECT * FROM principals WHERE event = 15821 AND person != 2?
>
> Sure, that's a concise answer to what I actually wrote, but it wasn't
> exactly what I intended :)
>
> Basically, what I've got is the first person and the
> tag_type. I can do
> it with a function from PHP:
>
> function get_spouses($p) {
> $handle = pg_query("select person from principals
> where event in (select event from principals
> where person = $p and tag_type = " .MARR. ")
> order by sort_date");
> $i=0;
> $spouses = array();
> while ($row = pg_fetch_row($handle) {
> if $row[0] != $p
> $spouses[$i++] = $row[0];
> }
> return $spouses;
> }
>
> But this is *ugly* ...
> --
> Leif Biberg Kristensen
> http://solumslekt.org/
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
>
The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer

Browse pgsql-sql by date

  From Date Subject
Next Message Daryl Richter 2005-09-22 20:26:01 Re: Updating cidr column with network operator
Previous Message Leif B. Kristensen 2005-09-22 18:12:15 Re: Help with a view