From: | "Greg Sabino Mullane" <greg(at)turnstep(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Cc: | spaceman-75e1f-20040422(at)ausgehaucht(dot)sensenmann(dot)at |
Subject: | Re: Counting rows from two tables in one query |
Date: | 2004-04-10 01:28:08 |
Message-ID: | f7bb0dd795c7fb17b53e1f20cc2cf765@biglumber.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
-----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(at)turnstep(dot)com
PGP Key: 0x14964AC8 200404092128
-----BEGIN PGP SIGNATURE-----
iD8DBQFAd03pvJuQZxSWSsgRAuDuAJ0elm2bPjgC1bGPHnrotzXrPKCt4ACdFytf
BglMm6IouFFZt1c19zST5ac=
=7DbY
-----END PGP SIGNATURE-----
From | Date | Subject | |
---|---|---|---|
Next Message | Rod Taylor | 2004-04-10 01:29:55 | Re: SQL challenge--top 10 for each key value? |
Previous Message | scott.marlowe | 2004-04-10 01:23:51 | Re: pgsql multi-database queries |