Re: Getting the latest unique items - Mailing list pgsql-sql

From Tomasz Myrta
Subject Re: Getting the latest unique items
Date
Msg-id 3DF84A2D.80004@klaster.net
Whole thread Raw
In response to Re: Getting the latest unique items  ("A.M." <agentm@cmu.edu>)
List 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



pgsql-sql by date:

Previous
From: Huub
Date:
Subject: primary + foreign key
Next
From: Tomasz Myrta
Date:
Subject: Re: primary + foreign key