diff --git a/mod/quiz/report/reportlib.php b/mod/quiz/report/reportlib.php
index <HASH>..<HASH> 100644
--- a/mod/quiz/report/reportlib.php
+++ b/mod/quiz/report/reportlib.php
@@ -99,7 +99,9 @@ function quiz_report_qm_filter_subselect($quiz){
         break;
     }
     if ($qmfilterattempts){
-        $qmsubselect = "(SELECT id FROM {$CFG->prefix}quiz_attempts WHERE u.id = userid ORDER BY $qmorderby LIMIT 1)=qa.id";
+        $qmsubselect = "(SELECT id FROM {$CFG->prefix}quiz_attempts " .
+                "WHERE quiz = {$quiz->id} AND u.id = userid " .
+                "ORDER BY $qmorderby LIMIT 1)=qa.id";
     } else {
         $qmsubselect = '';
     }
@@ -134,4 +136,4 @@ function quiz_report_highlighting_grading_method($quiz, $qmsubselect, $qmfilter)
                 ('<span class="highlight">'.quiz_get_grading_option_name($quiz->grademethod).'</span>'))."</p>";
     }
 }
-?>
\ No newline at end of file
+?>
MDL-<I> "Quiz Report: the quiz report do not find the first attempt" needed to include quiz id in WHERE conditions.

merged from <I> branch.