Re: [SQL] Getting the latest unique items

2002-12-12 Thread Tomasz Myrta
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 sco

Re: [SQL] Getting the latest unique items

2002-12-11 Thread Tom Lane
"A.M." <[EMAIL PROTECTED]> 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 expre

Re: [SQL] Getting the latest unique items

2002-12-11 Thread A.M.
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

Re: [SQL] Getting the latest unique items

2002-12-11 Thread Tomasz Myrta
I'm not sure if I understood your problem, but did you try with "distinct on"? select distinct on (id) from ... order by submittime desc Regards, Tomasz Myrta A.M. wrote: > I have a table as follows: > CREATE TABLE student_gradedmaterial( > id SERIAL, > studentid INT8 REFERENCES student

[SQL] Getting the latest unique items

2002-12-11 Thread A.M.
I have a table as follows: CREATE TABLE student_gradedmaterial( id SERIAL, studentid INT8 REFERENCES student, gradedmaterialid INT8 REFERENCES gradedmaterial, caid INT8 REFERENCES ca, ... submittime TIMESTAMP, gradedtime TIMESTAMP, score INT4 ); Every time a student submits a homewo