From: | Bill Moseley <moseley(at)hank(dot)org> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Help with a subselect inside a view |
Date: | 2005-08-25 15:19:25 |
Message-ID: | 20050825151925.GB14559@hank.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Thu, Aug 25, 2005 at 08:05:36AM -0500, Bruno Wolff III wrote:
> On Wed, Aug 24, 2005 at 23:12:17 -0700,
> Bill Moseley <moseley(at)hank(dot)org> wrote:
> > I need a little SQL help:
> >
> > I'm trying to get a subselect working inside a view.
>
> Unfortunately you didn't show us what you tried. My guess would be that
> you didn't enclose the subselect in parenthesis.
No, it wasn't that. I just didn't want to look too foolish. ;)
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.
> The distinct on solution that was suggested is probably a better way to
> go anyway.
Turns out it is, Thanks.
--
Bill Moseley
moseley(at)hank(dot)org
From | Date | Subject | |
---|---|---|---|
Next Message | Julio Cesar | 2005-08-25 15:20:41 | SOCKET Conection on Windwos 2003 vs PostgreSQL 8.0.1 |
Previous Message | Bill Moseley | 2005-08-25 15:01:26 | Re: Help with a subselect inside a view |