Mysql
 sql >> Base de données >  >> RDS >> Mysql

mysql-php interrogeant une liste pour construire une table

SELECT  tasks.*, students.*,
        (
        SELECT  grade
        FROM    grades
        WHERE   grades.task_id = tasks.task_id
                AND grades.username = students.username
        ORDER BY
                date DESC
        LIMIT 1
        ) AS lastgrade
FROM    assignments a
JOIN    assignment_tasks at
ON      at.assignmentID = a.assignmentID
JOIN    assignment_students ast
ON      ast.assignmentID = a.assignmentID
JOIN    tasks
ON      tasks.task_id = at.task_id
JOIN    students
ON      students.username = ast.username