I need to make a selection that will bring the last users who logged in without repeating the names. The problem is that the command below first groups and then sorts:
SELECT usuario FROM tab_logins GROUP BY usuario ORDER BY data_login desc
Table example:
usuario, data_login
joão, 2018-01-01
maria, 2018-01-02
jose, 2018-01-03
joão, 2018-01-04
antonio, 2018-01-05
joão, 2018-01-06
Using the command I mentioned. First it will group the names, and then it will sort, bringing the wrong result:
antonio
jose
maria
joao
Since the correct result would be this:
joão
antonio
jose
maria
Does anyone know how to solve it?