iTzMeRafa iTzMeRafa - 1 month ago 7
MySQL Question

SQL: How to get Min(Time) of a the same Name

I want to get ALL(*) Information WHERE a map has the best time.
So MIN(Time).

something like:

SELECT * FROM record_teamrace WHERE Map = min(Time)


But I cant do that, and I just want to see the best time, not all ranks of the same map.

Thanks for help, here is my database information:

record_teamrace

Answer

This sounds like a GROUP BY query is what you want:

SELECT Map, MIN(Time) AS minTime
FROM record_teamrace
GROUP BY Map

If you want to select all columns for each record, then you can use a join:

SELECT t1.*
FROM record_teamrace t1
INNER JOIN
(
    SELECT Map, MIN(Time) AS minTime
    FROM record_teamrace
    GROUP BY Map
) t2
    ON t1.Map  = t2.Map     AND
       t1.time = t2.minTime