Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
> I'm not clear how to move that "person_role.person = person.id" into the FROM statement. Does it matter? This should work: FROM person INNER JOIN person_role ON person.id = person_role.person LEFT OUTER JOIN instructors ON (person.id = instructors.person) LEFT OUTER JOIN class ON (instructor

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 02:06:35PM -0800, Bill Moseley wrote: > The now working query (thanks to you!) is: No that doesn't work. It's dropping the people that have never been assigned a class to teach (i.e. don't have a row in the "instructors" link table). > FROM class INNER JOIN ins

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 03:25:56PM -0600, John McCawley wrote: > I just noticed, also goofy is your ", person_role" in your from with no > criteria. I would generally put the "person_role.person = person.id" as > an INNER JOIN, and then only have the "person_role.role=3" in the > where. It doe

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
I just noticed, also goofy is your ", person_role" in your from with no criteria. I would generally put the "person_role.person = person.id" as an INNER JOIN, and then only have the "person_role.role=3" in the where. It doesn't look like that's the specific problem, but I generally find that

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread John McCawley
It looks to me like your problem is that weird area where you alias your inner join as "t" and thenn inner join based on this alias. You're getting a cartesian product somewhere, as evidenced by the "rows=700" in your explain. I already deleted the old mail with your table structure, but tr

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
On Mon, Nov 21, 2005 at 11:45:34AM -0600, Bruno Wolff III wrote: > On Mon, Nov 21, 2005 at 05:40:10 -0800, > Bill Moseley <[EMAIL PROTECTED]> wrote: > > > > Here's where I'm missing something. Trying to do an outer join on > > to bring in the class row with its class_time column: > > You don't

Re: [GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bruno Wolff III
On Mon, Nov 21, 2005 at 05:40:10 -0800, Bill Moseley <[EMAIL PROTECTED]> wrote: > > Here's where I'm missing something. Trying to do an outer join on > to bring in the class row with its class_time column: You don't say exactly why you are having a problem with this, but I think you would be b

[GENERAL] SQL Help: Multiple LEFT OUTER JOINs

2005-11-21 Thread Bill Moseley
I need to generate a table of teachers, and the count of classes they taught in the past and are scheduled to teach in the future. id | last_name | totalfuture_class_count | past_class_count -+--+--++- 3 | Smith |