Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 18485475AF8 for ; Fri, 1 Nov 2002 23:07:12 -0500 (EST) Received: from candle.pha.pa.us (momjian.navpoint.com [207.106.42.251]) by postgresql.org (Postfix) with ESMTP id 309AB475A7F for ; Fri, 1 Nov 2002 23:07:10 -0500 (EST) Received: (from pgman@localhost) by candle.pha.pa.us (8.11.6/8.10.1) id gA2474Y12040; Fri, 1 Nov 2002 23:07:04 -0500 (EST) From: Bruce Momjian Message-Id: <200211020407.gA2474Y12040@candle.pha.pa.us> Subject: Re: select syntax question In-Reply-To: <1036186412.25294.2.camel@Monet> To: Wei Weng Date: Fri, 1 Nov 2002 23:07:04 -0500 (EST) Cc: pgsql-sql@postgresql.org X-Mailer: ELM [version 2.4ME+ PL99 (25)] MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/30 X-Sequence-Number: 10172 Yes, a big difference. The first returns the distinct COUNT values, but there is only one, of course. The second returns the number of distinct values in the column. --------------------------------------------------------------------------- Wei Weng wrote: > This is what is on postgresql's manual page: > > http://www.postgresql.org/idocs/index.php?sql-select.html > > SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] > * | expression [ AS output_name ] [, ...] > [ FROM from_item [, ...] ] > [ WHERE condition ] > [ GROUP BY expression [, ...] ] > [ HAVING condition [, ...] ] > [ { UNION | INTERSECT | EXCEPT } [ ALL ] select ] > [ ORDER BY expression [ ASC | DESC | USING operator ] [, ...] ] > [ FOR UPDATE [ OF tablename [, ...] ] ] > [ LIMIT { count | ALL } ] > [ OFFSET start ] > > 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? > > Thanks! > > > -- > Wei Weng > Network Software Engineer > KenCast Inc. > > > > ---------------------------(end of broadcast)--------------------------- > TIP 4: Don't 'kill -9' the postmaster > -- Bruce Momjian | http://candle.pha.pa.us pgman@candle.pha.pa.us | (610) 359-1001 + If your life is a hard drive, | 13 Roberts Road + Christ can be your backup. | Newtown Square, Pennsylvania 19073