General developer forum

SQL query - obtain unique login users

 
Picture of JC Dodo
SQL query - obtain unique login users
 

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: -
Picture of Darko Miletić
Re: SQL query - obtain unique login users
Core developersParticularly helpful Moodlers


  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)
Picture of JC Dodo
Re: SQL query - obtain unique login users
 

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?


 
Average of ratings: -
Picture of Darko Miletić
Re: SQL query - obtain unique login users
Core developersParticularly helpful Moodlers

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

 
Average of ratings: Useful (1)
Picture of JC Dodo
Re: SQL query - obtain unique login users
 
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.
 
Average of ratings: -
Davo
Re: SQL query - obtain unique login users
Core developersParticularly helpful MoodlersPlugin 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.


 
Average of ratings: -