If multiple rows have the minimum or maximum value, which one is returned when using MAX/MIN?


#1

Question

If multiple rows have the minimum or maximum value, which one is returned when using MAX/MIN?

Answer

Typically, when you have more than one row that contains the minimum or maximum value in a column, the topmost row containing that value will be returned in the result.

For example, if the table contained multiple rows with the minimum price of 0.0, then the result of a query with MIN(price) will choose the topmost row from the table that had this price value.

Example

/* 
This should return the siliconphase app, because
it was the topmost row that had the minimum price 
value of the column. 
*/
SELECT id, name, MIN(price)
FROM fake_apps;