MySQL MIN / MAX all rows

I have a Races table with the rows ID , Name and TotalCP . I am SELECT MIN ( TotalCP ) FROM Races , but then I want to select the entire row that has the minimum value. How can I do this in a single request?

+3
source share
3 answers

General view to get the whole row from the aggregated value:

 SELECT * FROM Races WHERE TotalCP = (SELECT MIN(TotalCP) FROM Races) 

or

 SELECT r.* FROM ( SELECT MIN(TotalCP) t FROM Races ) m INNER JOIN Races r ON mt = r.TotalCP 

However, in this case, since you are using MIN , you can just sort and take the first line:

 SELECT * FROM Races ORDER BY TotalCP LIMIT 1 
+9
source
 Select * from Races where TotalCP = SELECT MIN( TotalCP ) FROM Races 
0
source

Subquery is your bid,

  SELECT * FROM Races where TotalCP = (SELECT MIN( TotalCP ) FROM Races) 
0
source

All Articles