SQL query - obtain unique login users

SQL query - obtain unique login users

by JC Dodo -
Number of replies: 5

Hi,


Would you mind to share what would be the appropriate mysql query to obtain unique login users on Moodle from 1st day of January 2018 to the current date?


Thanks!

Average of ratings: -
In reply to JC Dodo

Re: SQL query - obtain unique login users

by Darko Miletić -


  SELECT u.id, u.lastlogin 
    FROM mdl_user u
   WHERE u.deleted = 0 
         AND
         u.lastlogin >= UNIX_TIMESTAMP(TIMESTAMP('2018-01-01 00:00:00'))
GROUP BY u.id
ORDER BY u.lastlogin DESC



Average of ratings: Useful (2)
In reply to Darko Miletić

Re: SQL query - obtain unique login users

by JC Dodo -

You are the man Darko! Thanks!

How about from 1st of January 2018 to 31st of January 2018 with unique login users? How does the mysql query looks like?


In reply to JC Dodo

Re: SQL query - obtain unique login users

by Darko Miletić -

We are here to help a bit, not do your homework. Use common sense to figure this out.

Average of ratings: Useful (1)
In reply to Darko Miletić

Re: SQL query - obtain unique login users

by JC Dodo -
It seems this query is not working for Moodle version less than 2.6. When I run that query, there are no found for year 2018 but when in Moodle site at site administration on user list, I can see list of last access updated for 2018.
In reply to JC Dodo

Re: SQL query - obtain unique login users

by Davo Smith -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you're using a version of Moodle less than 2.6, then the very next thing you should do is to upgrade to a newer version of Moodle. Moodle 2.6 stopped receiving security fixes (let alone bug fixes) nearly 3 years ago and there are almost certainly known security problems with it now.