MySQL, Software Development

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 achieve 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

Loading

Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.


You Might Also Like