Alex Rivera | Logout

MIN/MAX vs ORDER BY and LIMIT

Asked 2009-01-09T01:25:10.377
142

Out of the following queries, which method would you consider the better one? What are your reasons (code efficiency, better maintainability, less WTFery)...

SELECT MIN(`field`)
FROM `tbl`;

SELECT `field`
FROM `tbl`
ORDER BY `field`
LIMIT 1;
Edit
Report

1 Answer

17
SELECT MIN(`field`)
FROM `tbl`;

Simply because it is ANSI compatible. Limit 1 is particular to MySql as TOP is to SQL Server.

answered 2009-01-09T01:28:17.890

Your Answer