Skip to content
Browse files

MDL-26371 sql - avoid distinct + text in lesson essay and report

  • Loading branch information...
1 parent 6d12bf2 commit 185f71c40d97090dbf98e4099c8d8f3199e3b1b3 @stronk7 stronk7 committed Feb 13, 2011
Showing with 20 additions and 14 deletions.
  1. +10 −7 mod/lesson/essay.php
  2. +10 −7 mod/lesson/report.php
View
17 mod/lesson/essay.php
@@ -31,12 +31,15 @@
if ($essayattempts = get_records_select('lesson_attempts', 'pageid IN('.implode(',', array_keys($pages)).')')) {
// Get all the users who have taken this lesson, order by their last name
if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
- $sql = "SELECT DISTINCT u.*
- FROM {$CFG->prefix}lesson_attempts a
- INNER JOIN {$CFG->prefix}user u ON u.id = a.userid
- INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
- INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
- WHERE a.lessonid = '$lesson->id'
+ $sql = "SELECT u.*
+ FROM {$CFG->prefix}user u
+ JOIN (
+ SELECT DISTINCT u.id
+ FROM {$CFG->prefix}lesson_attempts a
+ JOIN {$CFG->prefix}user u ON u.id = a.userid
+ JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
+ JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
+ WHERE a.lessonid = '$lesson->id') ui ON u.id = ui.id
ORDER BY u.lastname";
} else {
$sql = "SELECT u.*
@@ -367,4 +370,4 @@
}
print_footer($course);
-?>
+?>
View
17 mod/lesson/report.php
@@ -17,14 +17,17 @@
$nothingtodisplay = false;
list($cm, $course, $lesson) = lesson_get_basics($id);
-
+
if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
- $sql = "SELECT DISTINCT u.*
- FROM {$CFG->prefix}lesson_attempts a
- INNER JOIN {$CFG->prefix}user u ON u.id = a.userid
- INNER JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
- INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
- WHERE a.lessonid = '$lesson->id'
+ $sql = "SELECT u.*
+ FROM {$CFG->prefix}user u
+ JOIN (
+ SELECT DISTINCT u.id
+ FROM {$CFG->prefix}lesson_attempts a
+ JOIN {$CFG->prefix}user u ON u.id = a.userid
+ JOIN {$CFG->prefix}groups_members gm ON gm.userid = u.id
+ JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = {$cm->groupingid}
+ WHERE a.lessonid = '$lesson->id') ui ON u.id = ui.id
ORDER BY u.lastname";
} else {
$sql = "SELECT u.*

0 comments on commit 185f71c

Please sign in to comment.
Something went wrong with that request. Please try again.