pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <pgman@candle.pha.pa.us>
To: Wei Weng <wweng@kencast.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: select syntax question
Date: Fri, 1 Nov 2002 23:07:04 -0500 (EST)
Message-ID: <200211020407.gA2474Y12040@candle.pha.pa.us> (raw)
In-Reply-To: <1036186412.25294.2.camel@Monet>


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



view thread (3+ messages)

Message-ID: <200211020407.gA2474Y12040@candle.pha.pa.us>
Permalink:  ../200211020407.gA2474Y12040@candle.pha.pa.us/
Also on:    postgresql.org/message-id/200211020407.gA2474Y12040@candle.pha.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pgman@candle.pha.pa.us, wweng@kencast.com
  Subject: Re: select syntax question
  In-Reply-To: <200211020407.gA2474Y12040@candle.pha.pa.us>

* 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