X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 126B0D1D06C for ; Fri, 9 Apr 2004 22:28:09 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 18628-07 for ; Fri, 9 Apr 2004 22:28:09 -0300 (ADT) Received: from biglumber.com (biglumber.com [207.228.252.42]) by svr1.postgresql.org (Postfix) with SMTP id 0AEE9D1B989 for ; Fri, 9 Apr 2004 22:28:05 -0300 (ADT) Received: (qmail 1208 invoked from network); 10 Apr 2004 01:28:08 -0000 Received: from unknown (HELO localhost) (207.228.252.42) by 0 with SMTP; 10 Apr 2004 01:28:08 -0000 From: "Greg Sabino Mullane" To: pgsql-sql@postgresql.org Cc: spaceman-75e1f-20040422@ausgehaucht.sensenmann.at Cc: spaceman-75e1f-20040422@ausgehaucht.sensenmann.at Subject: Re: Counting rows from two tables in one query X-PGP-Key: 2529 DF6A B8F7 9407 E944 45B4 BC9B 9067 1496 4AC8 X-Request-PGP: http://www.biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8 In-Reply-To: <1928683.cthc5y6rJJ@weyoun.foo.at> Date: Sat, 10 Apr 2004 01:28:08 -0000 X-Mailer: JoyMail 1.47 Message-ID: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200404/86 X-Sequence-Number: 17461 -----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-----