From: Greg Sabino Mullane <greg@turnstep.com>
To: pgsql-sql@postgresql.org
Cc: spaceman-75e1f-20040422@ausgehaucht.sensenmann.at
Subject: Re: Counting rows from two tables in one query
Date: Sat, 10 Apr 2004 01:28:08 -0000
Message-ID: <f7bb0dd795c7fb17b53e1f20cc2cf765@biglumber.com> (raw)
In-Reply-To: <1928683.cthc5y6rJJ@weyoun.foo.at>
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> What I am trying to get is a list that shows how many records from
> 'sub_a' and 'sub_b' are referencing 'main':
SELECT id,
(SELECT COUNT(*) FROM sub_a WHERE sub_a.main_id=main.id),
(SELECT COUNT(*) FROM sub_b WHERE sub_b.main_id=main.id)
FROM main ORDER BY id;
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200404092128
-----BEGIN PGP SIGNATURE-----
iD8DBQFAd03pvJuQZxSWSsgRAuDuAJ0elm2bPjgC1bGPHnrotzXrPKCt4ACdFytf
BglMm6IouFFZt1c19zST5ac=
=7DbY
-----END PGP SIGNATURE-----
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: greg@turnstep.com, spaceman-75e1f-20040422@ausgehaucht.sensenmann.at
Subject: Re: Counting rows from two tables in one query
In-Reply-To: <f7bb0dd795c7fb17b53e1f20cc2cf765@biglumber.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox