| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
|---|---|
| To: | "A(dot)M(dot)" <agentm(at)cmu(dot)edu> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: Getting the latest unique items |
| Date: | 2002-12-12 07:13:29 |
| Message-ID: | 4081.1039677209@sss.pgh.pa.us |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
"A.M." <agentm(at)cmu(dot)edu> writes:
> When I try to run the following query:
> select distinct on(student_gradedmaterial.id) ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> ... order by submittime desc;
^^^^^^^^^^^^^^^^^^^
> I get the following error:
> ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY
> expressions
Indeed. You might benefit from reading the DISTINCT ON usage example
given in the SELECT reference page,
http://www.ca.postgresql.org/users-lounge/docs/7.3/postgres/sql-select.html
(see under "Description"). Basically, DISTINCT ON is *only* useful when
designed hand-in-hand with an ORDER BY ...
regards, tom lane
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Ludwig Lim | 2002-12-12 08:04:17 | Re: Primary Key Help ! |
| Previous Message | A.M. | 2002-12-12 05:14:22 | Re: Getting the latest unique items |