I have two tables:
STUDENT GRADES ---------- ---------- id id name person_id address date city test_name phone grade
Each student will have several entries in the Grad table. I am wondering if it is possible using SQL (Postgres) to select all students along with their latest class information. Basically, I want the result table to look like this: date, test_name and grade - for the last result (by date).
LATEST_GRADES ---------------- id name address city phone grade_id date test_name grade
Any help would be greatly appreciated, thanks.
EDIT: ADDED SOLUTION SOLUTIONS
SELECT * FROM students s JOIN (SELECT DISTINCT ON (person_id) person_id, date, test_name, grade FROM grades ORDER BY person_id, date DESC) g ON s.id = g.person_id;
PKKid source share