Hi,
Currently using Moodle 3.8. Not a SQL expert, but have had some success, but as noted, some question marks surrounding two similar reports. The goal is to have a report that (#1) lists all users and the last login date. The report needs to (#2) include user profile fields so we can export and filter. I started with #1. I had success with the following:
/*ALL LOGINS*/
SELECT id, username, FROM_UNIXTIME( lastlogin ) as lastlogin
FROM prefix_user
However when trying to add in some custom user profile fields with the following SQL, the profile fields appear as expected, but the results are much less (382). They are mix of results. Some with the 1969 date. Not all of the user profile fields are populated in the LMS. The user profile fields values appear to be correct. But I'm not sure why the results are so much less. I was expecting the same as above but with user profile fields. Is there anything in this sql that would filter different than above?
SELECT u.username,FROM_UNIXTIME( lastlogin ) as lastlogin,d1.data AS 'Vertical', d2.data As 'Entity'
FROM prefix_user u
JOIN prefix_user_info_data d1 ON d1.userid = u.id
JOIN prefix_user_info_field f1 ON d1.fieldid = f1.id AND f1.shortname = 'vertical'
JOIN prefix_user_info_data d2 ON d2.userid = u.id
JOIN prefix_user_info_field f2 ON d2.fieldid = f2.id AND f2.shortname = 'entity'