MariaDB [teeworlds]> EXPLAIN SELECT * FROM (SELECT *, dense_rank() OVER (PARTITION BY Map ORDER BY TIME) as rank FROM record_race) AS a WHERE a.rank=1; +------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+ | 1 | PRIMARY | | ALL | NULL | NULL | NULL | NULL | 4298976 | Using where | | 2 | DERIVED | record_race | ALL | NULL | NULL | NULL | NULL | 4298976 | Using temporary | +------+-------------+-------------+------+---------------+------+---------+------+---------+-----------------+ 2 rows in set (0.073 sec) MariaDB [teeworlds]> EXPLAIN SELECT r1s.map, name, timestamp, time FROM record_race AS ranks INNER JOIN (SELECT map, MIN(time) AS mintime FROM record_race GROUP BY map) AS r1s ON ranks.map = r1s.map AND ranks.time = r1s.mintime ORDER BY timestamp LIMIT 10; +------+-------------+-------------+-------+------------------------+-----------+---------+------------------------------------------+---------+----------------------------------------------+ | id | select_type | table | type | possible_keys | key | key_len | ref | rows | Extra | +------+-------------+-------------+-------+------------------------+-----------+---------+------------------------------------------+---------+----------------------------------------------+ | 1 | PRIMARY | ranks | index | Map,Map_2,MapTimestamp | Timestamp | 8 | NULL | 1 | Using index | | 1 | PRIMARY | | ref | key0 | key0 | 519 | teeworlds.ranks.Map,teeworlds.ranks.Time | 10 | | | 2 | DERIVED | record_race | index | Map,Map_2,MapTimestamp | Timestamp | 8 | NULL | 4298976 | Using index; Using temporary; Using filesort | +------+-------------+-------------+-------+------------------------+-----------+---------+------------------------------------------+---------+----------------------------------------------+ 3 rows in set (0.000 sec)