Re: Help with a subselect inside a view - Mailing list pgsql-general

From Bruno Wolff III
Subject Re: Help with a subselect inside a view
Date
Msg-id 20050825201300.GA22712@wolff.to
Whole thread Raw
In response to Re: Help with a subselect inside a view  (Bill Moseley <moseley@hank.org>)
List pgsql-general
On Thu, Aug 25, 2005 at 08:19:25 -0700,
  Bill Moseley <moseley@hank.org> wrote:
>
> DROP VIEW cl;
> CREATE VIEW cl  (id, instructor)
>     AS
>         SELECT class.id, person.first_name
>           FROM class, instructors, person
>          WHERE instructors.person = person.id
>            AND class.id = (
>                    SELECT instructors.id
>                      FROM instructors, person
>                     WHERE instructors.class = class.id
>                       AND person.id = instructors.person
>                     LIMIT 1
>                 );
>
> Which returns a row for every row in "instructors" table.

I think if you were to use this approach you would do something more like:

DROP VIEW cl;
CREATE VIEW cl  (id, instructor)
    AS
        SELECT class.id,
            (SELECT person.first_name
               FROM instructors, person
               WHERE instructors.class = class.id
                 AND person.id = instructors.person
               LIMIT 1)
          FROM class;

pgsql-general by date:

Previous
From: Steve Atkins
Date:
Subject: Re: Postgresql replication
Next
From: "Matt A."
Date:
Subject: help