Top ten

from the Artful Common Queries page


We often want to know the top 1, 2, 10 or whatever values from a query. This is dead simple in MySQL. However many Joins and Wheres the query has, simply Order By the column(s) whose highest values are sought, and Limit the resultset:
  SELECT (somecolumn), (othercolumns) ...
  FROM (some tables) ...
  ORDER BY somecolumn DESC
  LIMIT 10;

Last updated 3 Mar 2025