Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bruno Wolff III
On Thu, Aug 25, 2005 at 08:19:25 -0700, Bill Moseley <[EMAIL PROTECTED]> 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

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Tom Lane
Bill Moseley <[EMAIL PROTECTED]> writes: > On Thu, Aug 25, 2005 at 12:14:31PM -0400, Tom Lane wrote: >> It's fairly pointless though, because as the manual notes, you can't get >> any well-defined behavior without additional ORDER BY columns to >> prioritize the rows within class.id groups. As is,

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bill Moseley
On Thu, Aug 25, 2005 at 12:14:31PM -0400, Tom Lane wrote: > > CREATE VIEW cl (id, class_time, instructor) > > AS > > SELECT DISTINCT ON(class.id) > >class.id, class.class_time, person.first_name > > FROM class, instructors, person > >

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Tom Lane
Bill Moseley <[EMAIL PROTECTED]> writes: >> http://www.postgresql.org/docs/current/static/sql-select.html#SQL-DISTINCT >The DISTINCT ON expression(s) must match the leftmost ORDER BY >expression(s). The ORDER BY clause will normally contain additional >expression(s) that determine the

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bill Moseley
And about being efficient: On Thu, Aug 25, 2005 at 08:01:26AM -0700, Bill Moseley wrote: > DROP VIEW cl; > CREATE VIEW cl (id, class_time, instructor) > AS > SELECT DISTINCT ON(class.id) >class.id, class.class_time, person.first_name >

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bill Moseley
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 <[EMAIL PROTECTED]> 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

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bill Moseley
Hi David, On Thu, Aug 25, 2005 at 01:22:02AM -0700, David Fetter wrote: > This sounds like a case for PostgreSQL's nifty DISTINCT ON functionality. > > http://www.postgresql.org/docs/current/static/sql-select.html#SQL-DISTINCT The DISTINCT ON expression(s) must match the leftmost ORDER BY

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread Bruno Wolff III
On Wed, Aug 24, 2005 at 23:12:17 -0700, Bill Moseley <[EMAIL PROTECTED]> 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. The dist

Re: [GENERAL] Help with a subselect inside a view

2005-08-25 Thread David Fetter
On Wed, Aug 24, 2005 at 11:12:17PM -0700, Bill Moseley wrote: > I need a little SQL help: > > I'm trying to get a subselect working inside a view. > > I have a table "class" that has related tables (a class has a > location, a location has an address with columns city, state, zip). > I want to us

[GENERAL] Help with a subselect inside a view

2005-08-24 Thread Bill Moseley
I need a little SQL help: I'm trying to get a subselect working inside a view. I have a table "class" that has related tables (a class has a location, a location has an address with columns city, state, zip). I want to use a VIEW to display columns related to a given class. But a class can also