Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by mail.postgresql.org (8.11.3/8.11.1) with ESMTP id f2JNqTN16145 for ; Mon, 19 Mar 2001 18:52:29 -0500 (EST) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 26888; Mon, 19 Mar 2001 15:52:27 -0800 From: "Josh Berkus" Subject: Re: count() and multiple tables To: Joseph Shraibman Cc: pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Mon, 19 Mar 2001 15:52:27 -0800 Message-ID: In-Reply-To: <3AB6983A.E64A6AD6@selectacast.net> MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit X-Archive-Number: 200103/379 X-Sequence-Number: 2045 Joseph, SImple as pie (e.g., easy on your 100th one): > select count(*) from d where status = 2 and d.id = u.dkey and > u.status = > 2 and not u.b and u.akey = a.key and a.status = 3; Count(*) will always count the number of records in the largest table in your join. If you want the number of records in a specific table, then you have to make sure that that table is the only on in your FROM clause, and reference all other tables in WHERE: select count(*) from d where id IN (select u.dkey from u, a where u.akey = a.key AND u.status = 2 and not u.b and a.status = 3); -Josh Berkus ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco