Mysql query problem

后端 未结 8 922
逝去的感伤
逝去的感伤 2020-12-22 03:24

I have a problem with my mysql query.

My database:

sections
id
section_name

grades
id
user_id
section_id
date
grade

I want my data

8条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 03:52

    My solution involves the use of subquery to get the id of the latest grade and then passing it up to the query which then joins both sections and grades table to return section_name and grade. Please consider this more as a psuedocode than a valid sql query as I dont have time to test it. Might come back later to edit it

    SELECT section_name, grade FROM sections, grades WHERE sections.id = grades.id AND grades.id = (SELECT id FROM grades WHERE section_id = '$Id' ORDER by date DESC LIMIT 1)

提交回复
热议问题