From: | Bruno Wolff III <bruno(at)wolff(dot)to> |
---|---|
To: | Bill Moseley <moseley(at)hank(dot)org> |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Help with a subselect inside a view |
Date: | 2005-08-25 20:13:00 |
Message-ID: | 20050825201300.GA22712@wolff.to |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Aug 25, 2005 at 08:19:25 -0700,
Bill Moseley <moseley(at)hank(dot)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;
From | Date | Subject | |
---|---|---|---|
Next Message | Matt A. | 2005-08-25 20:44:52 | help |
Previous Message | Steve Atkins | 2005-08-25 20:05:19 | Re: Postgresql replication |