How to obtain all distinct items but limit each distinct to max n and ordered by date?
Apparently below query solves the issue and gives me recent 10 records for each command_name ordered by command name and when it started.

select
    s1.* 
from
    sync_logs as s1
left join 
    sync_logs as s2 
on 
    s1.command_name = s2.command_name and 
    s1.command_start &lt;= s2.command_start
group by 
    s1.uuid
having 
    count(*) &lt;= 10
order by 
    command_name asc, 
    command_start desc;