I'm trying to create a report that has user information, completion, and custom profile fields data as headings.
I can select users joined to their course completion records fine, it's something like
select u.email Email, u.firstname GivenName, u.lastname Surname, s.fullname Course, case when c.`timestarted` > 0 then from_unixtime(c.`timestarted`, '%Y %M %D %h:%i:%s') else 'Never' End Started, case when c.`timecompleted` > 0 then from_unixtime(c.`timecompleted`, '%Y %M %D %h:%i:%s') else 'Never' end Completed, c.*
from mdl_user u left outer join mdl_course_completions c
on u.id = c.`userid`
inner join mdl_course s on c.`course` = s.`id`
I've also figured out how to make my user profile fields appear as columns on a [separate] select statement
select
max(if(f.shortname = 'RegType',i.data, NULL)) AS RegistrationType,
max(if(f.shortname = 'REGnum',i.data, NULL)) AS RegistrationNumber,
max(if(f.shortname = 'GradYear',i.data, NULL)) AS GraduationYear,
max(if(f.shortname = 'Address',i.data, NULL)) AS Address,
max(if(f.shortname = 'DOB1', DATE_FORMAT(DATE_ADD(FROM_UNIXTIME(0), INTERVAL + i.data SECOND), '%D %M %Y'), NULL)) AS DOB,
max(if(f.shortname = 'gender',i.data, NULL)) AS Gender
from (
(mdl_user_info_data i join mdl_user_info_field f on i.fieldid = f.id join mdl_user u on i.userid = u.id)
) group by i.`userid`
but I can't seem to figure out how to take the columns both selects and join them together so the report has all those column from both queries (given some users may not have any custom profile fields defined, I still want those users to show). Any pointers?