query problem - get count in related table - Mailing list pgsql-novice

From Rory Campbell-Lange
Subject query problem - get count in related table
Date
Msg-id 20020523173104.GA15057@campbell-lange.net
Whole thread Raw
Responses Re: query problem - get count in related table
List pgsql-novice
Thanks to everyone on the list I'm up and running with postgres.

I'm having trouble doing a query:

table a          |    table b
------------------------------
    id     data  |        id
------------------------------
    1       2     |        2
    2      1     |        2
    3      4     |        1
                 |        1
                 |        1
                 |        3

I'd like to run a query that returned the following results:

 a.id  a.data  count(b.id where b.id = a.data)
 ---------------------------------------------
 1     2       2
 2     1       3
 3     4       0

Thanks for any help.
Rory

--
Rory Campbell-Lange
<rory@campbell-lange.net>
<www.campbell-lange.net>

pgsql-novice by date:

Previous
From: Rory Campbell-Lange
Date:
Subject: use vi mode in psql
Next
From: "Adam Erickson"
Date:
Subject: Re: when to use char, varchar or text