Re: Dumb question about count()

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Benjamin Smith <lists(at)benjamindsmith(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Dumb question about count()
Date: 2005-07-22 05:35:08
Message-ID: 20050722053507.GA13925@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jul 21, 2005 at 10:09:07PM -0700, Benjamin Smith wrote:
> select classroom.title,
> count(students.id) AS students,
> count(seats.id) AS seats
> from classrooms, students, seats
> where classrooms.id=students.classrooms_id
> and classrooms.id=seats.id
>
> Except that it counts 0s for seats/students.
>
> Why can't I recall/find how to do this particular join?

Sounds like you're looking for an outer join.

http://www.postgresql.org/docs/8.0/static/tutorial-join.html
http://www.postgresql.org/docs/8.0/static/queries-table-expressions.html#QUERIES-FROM

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Rose, Juergen 2005-07-22 07:10:01 Re: Insert into ... Select ... From ... too intelligent transaction
Previous Message Bruce Momjian 2005-07-22 05:14:44 Re: Strange input/cast semantics for inet