Hello folks.
I am getting close.. running rhel 6.8, php 7.3.4 moodle 3.9.4 and mysql 5.7
I wrote a query to find out which courses have students (identified using their email and not via roleid) that have enrolled BOTH via "database" and "manual" method but having problems trying to find their course id.
The purpose is to delete the "database" method only IF BOTH exist. For example if course A has a student who was enrolled BOTH via DB and Manual enrolment plugin, I want to delete their "db method" and leave their "manual" intact. Again only when both occur. If not, then it skips to next record. This is in preparation to start a new and clean db enrolment method moving forward with new enrolments .
this is my sample query for now. I don't know how to get it to show on the query result the course id if I do not selectively choose one, as shown in my example:
SELECT userid , enrolid FROM mdl_user_enrolments WHERE enrolid IN (Select e.id FROM mdl_enrol e where (e.enrol ='database' or e.enrol='manual') and e.courseid IN (SELECT c.id FROM mdl_role_assignments ra, mdl_user u, mdl_course c, mdl_context cxt WHERE ra.userid = u.id AND ra.contextid = cxt.id AND cxt.contextlevel =50 AND cxt.instanceid = c.id AND roleid =5 AND u.email like '%@student.school.com%' and c.id ='XXXXXX'));
Note the dupes in the userid column. the enrolid contain both the enrolment id's of manual and db of course
+--------+---------+
| userid | enrolid |
+--------+---------+
| 142276 | 33442 |
| 145150 | 33442 |
| 145181 | 33442 |
| 145417 | 33442 |
| 145420 | 33442 |
| 145422 | 33442 |
| 145428 | 33442 |
| 145863 | 33442 |
| 145870 | 33442 |
| 146019 | 33442 |
| 146020 | 33442 |
| 146022 | 33442 |
| 146023 | 33442 |
| 146024 | 33442 |
| 146026 | 33442 |
| 146193 | 33442 |
| 146197 | 33442 |
| 146327 | 33442 |
| 146328 | 33442 |
| 148172 | 33442 |
| 148661 | 33442 |
| 163621 | 33442 |
| 142276 | 33477 |
| 145150 | 33477 |
| 145181 | 33477 |
| 145417 | 33477 |
| 145420 | 33477 |
| 145422 | 33477 |
| 145428 | 33477 |
| 145863 | 33477 |
| 145870 | 33477 |
| 146019 | 33477 |
| 146020 | 33477 |
| 146022 | 33477 |
| 146023 | 33477 |
| 146024 | 33477 |
| 146026 | 33477 |
| 146193 | 33477 |
| 146197 | 33477 |
| 146327 | 33477 |
| 146328 | 33477 |
| 148172 | 33477 |
| 148661 | 33477 |
+--------+---------+
43 rows in set (0.00 sec)
How can I change my query?
Thank you