Re: Count the children - Mailing list pgsql-novice

From Sean Davis
Subject Re: Count the children
Date
Msg-id 264855a00908180750r63520c25q7f7387824901e111@mail.gmail.com
Whole thread Raw
In response to Count the children  (Michael Rowan <mike.rowan@internode.on.net>)
Responses Re: Count the children
List pgsql-novice


On Tue, Aug 18, 2009 at 10:34 AM, Michael Rowan <mike.rowan@internode.on.net> wrote:
I need what sounds like a very simple query - but I'm darned if I can figure it out.

I have two tables, parent and child related by child.parent_id = parent.id
The query should return, for each parent row, parent.name and number of child rows

Hi, Michael.

select parent.name,count(*) from parent join child on child.parent_id=parent.id;

Or am I missing something a subtlety?

Sean


pgsql-novice by date:

Previous
From: Michael Rowan
Date:
Subject: Count the children
Next
From: Mark Styles
Date:
Subject: Re: Count the children