Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 7ABD6476315 for ; Fri, 1 Nov 2002 16:49:38 -0500 (EST) Received: from wolff.to (unknown [66.93.197.35]) by postgresql.org (Postfix) with SMTP id AE7A8475FD9 for ; Fri, 1 Nov 2002 16:49:37 -0500 (EST) Received: (qmail 2312 invoked by uid 500); 1 Nov 2002 21:59:00 -0000 Date: Fri, 1 Nov 2002 15:59:00 -0600 From: Bruno Wolff III To: Wei Weng Cc: pgsql-sql@postgresql.org Subject: Re: select syntax question Message-ID: <20021101215900.GA2290@wolff.to> Mail-Followup-To: Wei Weng , pgsql-sql@postgresql.org References: <1036186412.25294.2.camel@Monet> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1036186412.25294.2.camel@Monet> User-Agent: Mutt/1.3.25i X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/21 X-Sequence-Number: 10163 On Fri, Nov 01, 2002 at 16:33:32 -0500, Wei Weng wrote: > This is what is on postgresql's manual page: > > According to this syntax, SELECT DISTINCT COUNT(ID) FROM test > should be valid while SELECT COUNT(DISTINCT ID) FROM test otherwise. > > while in fact, both are valid. > > Is there any difference between this two queries? They mean different things. The first will return the number of rows with non-null values for id. Since only one row is returned it is guarenteed to be distinct so the distinct keyword will have no effect. The second form will return the number of distinct, non-null values for id in the table.