For MySQL 8 you can use row_number
analytic function to order your timestamps inside the day in descending order, and then select the first item per group. No tricky aggregation, limiting and joins, it just assigns the number according to the order and grouping, the rest of the row is unchanged.
with a as (
select 1 as id, 5 as userid, timestamp '2021-01-01 00:05:50' as logindate union all
select 2, 7, timestamp '2021-01-01 06:06:50' union all
select 3, 5, timestamp '2021-01-01 06:34:50' union all
select 4, 3, timestamp '2021-01-02 06:56:56' union all
select 5, 3, timestamp '2021-01-02 15:46:52'
)
, rn as (
select a.*,
row_number() over(
partition by
userid,
date(logindate)
order by
logindate desc
) as __rn
from a
)
select *
from rn
where __rn = 1
order by userid desc
id | userid | logindate | __rn
-: | -----: | :------------------ | ---:
2 | 7 | 2021-01-01 06:06:50 | 1
3 | 5 | 2021-01-01 06:34:50 | 1
5 | 3 | 2021-01-02 15:46:52 | 1
db<>fiddle here