简体   繁体   中英

Simple MySql - Get Largest Number in Table

I need to use the MySQL Order By function in a query except I need it to be in reverse order by number - therefore like 45, 32, 12, 10 instead of 10, 12, 32, 45. I would then limit it to 1 so I would get the highest number in the list. However if you have another way to do this that would be great thanks :D

Anyway thanks for your help!

Christian Stewart

Two options - using LIMIT:

  SELECT yt.numeric_column
    FROM YOUR_TABLE yt
ORDER BY yt.numeric_column DESC
   LIMIT 1

Using MAX:

SELECT MAX(yt.numeric_column)
  FROM YOUR_TABLE yt

you want: ORDER BY numeric_column DESC

the DESC reverses it. (You can then add LIMIT after that)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM