Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 9A8D5475DC0 for ; Thu, 12 Dec 2002 03:32:31 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id E8752475DD7 for ; Thu, 12 Dec 2002 03:32:30 -0500 (EST) Received: from klaster.net (pr192.krakow.cvx.ppp.tpnet.pl [213.76.42.192]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 82D542B266; Thu, 12 Dec 2002 09:17:16 +0100 (CET) Message-ID: <3DF84A2D.80004@klaster.net> Date: Thu, 12 Dec 2002 09:34:53 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; en-US; rv:1.2b) Gecko/20021016 X-Accept-Language: en-us, en MIME-Version: 1.0 To: "A.M." Cc: pgsql-sql@postgresql.org Subject: Re: Getting the latest unique items References: <9352B184-0D90-11D7-BA9C-0030657192DA@cmu.edu> In-Reply-To: <9352B184-0D90-11D7-BA9C-0030657192DA@cmu.edu> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/147 X-Sequence-Number: 10735 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