我有一个为我正在维护的应用程序编写的查询,它用于检查某个学生的结果,其他学生的结果也正常,但对于某些学生,它返回Query error: Subquery returns more than 1 row
$this->db->query("SELECT subjects.name AS subject, subjects.id as subject_id, marks.CA AS ca, marks.exam AS exam, marks.mark_obtained AS total, marks.percentages AS percentages, marks.student_id, marks.subject_id, marks.class_id, marks.section_id, marks.session, marks.term, marks.school_id, (SELECT grades.name FROM grades WHERE marks.mark_obtained >= grades.mark_from AND marks.mark_obtained <= grades.mark_upto AND grades.school_id=$school_id) AS grade, (SELECT grades.comment FROM grades WHERE marks.mark_obtained >= grades.mark_from AND marks.mark_obtained <= grades.mark_upto AND grades.school_id=$school_id) AS remark FROM users INNER JOIN students ON users.id = students.user_id INNER JOIN marks ON students.id = marks.student_id INNER JOIN subjects ON marks.subject_id = subjects.id WHERE marks.school_id = ? AND marks.student_id = ? AND marks.session = ? AND marks.term = ? AND marks.class_id = ? AND marks.section_id = ? ORDER BY marks.subject_id", array($school_id, $student_id, $session_id, $term, $class_id, $section_id))->result_array();
1条答案
按热度按时间yyyllmsg1#
在查询中使用top 1,如下所示