Retrieve maximal / minimal record
问题 A rather complicated SQL query I was working on got me thinking about a limitation of (ANSI) SQL: Is there a way to retrieve a record that is maximal or minimal with respect to an arbitrary ordering? In other words: Given a query like this: SELECT * FROM mytable WHERE <various conditions> ORDER BY <order clause> is it possible to write a query that returns only the first row (possibly by transforming the order clause into something else)? I know you can do this using LIMIT (MySQL) / ROWNUM