Postgresql select row with minimum value by certain column?
If you're not worrying about ties, then use the PostgreSQL extension for DISTINCT ON

SELECT DISTINCT ON (id) id, student, grade, subject
FROM table
ORDER BY id, grade;