pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedselect syntax question
3+ messages / 3 participants
[nested] [flat]
* select syntax question
@ 2002-11-01 21:33 Wei Weng <wweng@kencast.com>
0 siblings, 2 replies; 3+ messages in thread
From: Wei Weng @ 2002-11-01 21:33 UTC (permalink / raw)
To: pgsql-sql
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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: select syntax question
@ 2002-11-01 21:59 Bruno Wolff III <bruno@wolff.to>
parent: Wei Weng <wweng@kencast.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bruno Wolff III @ 2002-11-01 21:59 UTC (permalink / raw)
To: Wei Weng <wweng@kencast.com>; +Cc: pgsql-sql
On Fri, Nov 01, 2002 at 16:33:32 -0500,
Wei Weng <wweng@kencast.com> 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.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: select syntax question
@ 2002-11-02 04:07 Bruce Momjian <pgman@candle.pha.pa.us>
parent: Wei Weng <wweng@kencast.com>
1 sibling, 0 replies; 3+ messages in thread
From: Bruce Momjian @ 2002-11-02 04:07 UTC (permalink / raw)
To: Wei Weng <wweng@kencast.com>; +Cc: 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@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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2002-11-02 04:07 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-11-01 21:33 select syntax question Wei Weng <wweng@kencast.com>
2002-11-01 21:59 ` Bruno Wolff III <bruno@wolff.to>
2002-11-02 04:07 ` Bruce Momjian <pgman@candle.pha.pa.us>
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