0

Top n values without using a limit clause or its equivalent

I came across this exam question several times in the past about how to get some top n values without using the LIMIT clause or its equivalent in other RDBMS (e.g., FIRST n in Informix) but never really gave it serious thought until today. I would skip the item and press on.

To achive this, use a subquery. The following SQL SELECT statement retrieves the top 10 highest values from table T1.

mysql001

Sample data

mysql002

Retrieved top 10 highest values