From: | Bruce Momjian <pgman(at)candle(dot)pha(dot)pa(dot)us> |
---|---|
To: | Wei Weng <wweng(at)kencast(dot)com> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: select syntax question |
Date: | 2002-11-02 04:07:04 |
Message-ID: | 200211020407.gA2474Y12040@candle.pha.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at)candle(dot)pha(dot)pa(dot)us | (610) 359-1001
+ If your life is a hard drive, | 13 Roberts Road
+ Christ can be your backup. | Newtown Square, Pennsylvania 19073
From | Date | Subject | |
---|---|---|---|
Next Message | Ken Kennedy | 2002-11-02 06:56:54 | Timezone issue with date_part |
Previous Message | Bruce Momjian | 2002-11-02 03:48:00 | Re: Different size in the DATA directory |