Re: Count the children

From: Sean Davis <sdavis2(at)mail(dot)nih(dot)gov>
To: Michael Rowan <mike(dot)rowan(at)internode(dot)on(dot)net>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Count the children
Date: 2009-08-18 14:50:03
Message-ID: 264855a00908180750r63520c25q7f7387824901e111@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Tue, Aug 18, 2009 at 10:34 AM, Michael Rowan <mike(dot)rowan(at)internode(dot)on(dot)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

In response to

Responses

Browse pgsql-novice by date

  From Date Subject
Next Message Sean Davis 2009-08-18 15:07:52 Re: Count the children
Previous Message Mark Styles 2009-08-18 14:44:00 Re: Count the children