Re: Getting the latest unique items

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
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 08:34:53
Message-ID: 3DF84A2D.80004@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

A.M. wrote:

> When I try to run the following query:
>
> select distinct on(student_gradedmaterial.id) student_gradedmaterial.id
> from coursesection_student,student_gradedmaterial WHERE
> gradedmaterialid=1 AND
> coursesection_student.studentid=student_gradedmaterial.studentid AND
> coursesectionid=1 and score is not null order by submittime desc;
>
> I get the following error:
>
> ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY
> expressions

No
You have to change your sort order (as in error above). It should be:
order by student_gradematerial.id asc, submittime desc;
Tomasz Myrta

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Tomasz Myrta 2002-12-12 08:54:25 Re: primary + foreign key
Previous Message Huub 2002-12-12 08:29:29 primary + foreign key