MDL-22910 Fixed regression - problem with DISTINCT + text field in MSSQL/Oracle

This commit is contained in:
David Mudrak
2010-07-20 09:02:23 +00:00
parent 69531afc68
commit c6575befff
+7 -4
View File
@@ -1172,13 +1172,16 @@ function get_my_remotecourses($userid=0) {
$userid = $USER->id;
}
$sql = "SELECT DISTINCT c.id, c.remoteid, c.shortname, c.fullname,
// we can not use SELECT DISTINCT + text field (summary) because of MS SQL and Oracle, subselect used therefore
$sql = "SELECT c.id, c.remoteid, c.shortname, c.fullname,
c.hostid, c.summary, c.summaryformat, c.categoryname AS cat_name,
h.name AS hostname
FROM {mnetservice_enrol_courses} c
JOIN {mnetservice_enrol_enrolments} e ON (e.hostid = c.hostid AND e.remotecourseid = c.remoteid)
JOIN {mnet_host} h ON h.id = c.hostid
WHERE e.userid = ?";
JOIN (SELECT DISTINCT hostid, remotecourseid
FROM {mnetservice_enrol_enrolments}
WHERE userid = ?
) e ON (e.hostid = c.hostid AND e.remotecourseid = c.remoteid)
JOIN {mnet_host} h ON h.id = c.hostid";
return $DB->get_records_sql($sql, array($userid));
}