[GENERAL] Counting records in a child table

2011-03-31 Thread Mike Orr
I know how to do count(*)/group by on a single table, but how do I get a count of related records in a child table? Some of the counts will be zero. SELECT parent.id AS id, parent.name AS name, parent.create_date AS create_date, COUNT(child.id) AS count FROM parent LEFT JOIN child

Re: [GENERAL] Counting records in a child table

2011-03-31 Thread David Johnston
Message- From: pgsql-general-ow...@postgresql.org [mailto:pgsql-general-ow...@postgresql.org] On Behalf Of Mike Orr Sent: Thursday, March 31, 2011 2:49 PM To: pgsql-general@postgresql.org Subject: [GENERAL] Counting records in a child table I know how to do count(*)/group by on a single table

Re: [GENERAL] Counting records in a child table

2011-03-31 Thread Mike Orr
...@postgresql.org] On Behalf Of Mike Orr Sent: Thursday, March 31, 2011 2:49 PM To: pgsql-general@postgresql.org Subject: [GENERAL] Counting records in a child table I know how to do count(*)/group by on a single table, but how do I get a count of related records in a child table? Some of the counts

Re: [GENERAL] Counting records in a child table

2011-03-31 Thread David Johnston
-general@postgresql.org Subject: Re: [GENERAL] Counting records in a child table Thanks. How would I do it with a window function? I thought windows only compared groups of records in the same table. -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your