From: Josh Berkus <josh@agliodbs.com>
To: Joseph Shraibman <jks@selectacast.net>
Cc: pgsql-sql@postgresql.org
Subject: Re: count() and multiple tables
Date: Mon, 19 Mar 2001 15:52:27 -0800
Message-ID: <web-26888@davinci.ethosmedia.com> (raw)
In-Reply-To: <3AB6983A.E64A6AD6@selectacast.net>
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
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: josh@agliodbs.com, jks@selectacast.net
Subject: Re: count() and multiple tables
In-Reply-To: <web-26888@davinci.ethosmedia.com>
References: <3AB6983A.E64A6AD6@selectacast.net> <web-26888@davinci.ethosmedia.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