Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   MySQL (https://www.askmehelpdesk.com/forumdisplay.php?f=442)
-   -   How to get the highest number only as output in sql (https://www.askmehelpdesk.com/showthread.php?t=88142)

  • May 1, 2007, 12:08 PM
    alfredlionel
    How to get the highest number only as output in sql
    Dear sir ,
    I would like to know how to get the highest number as display.Fpr example a set of ages are in the database.I need only the highest age as output
  • May 5, 2007, 08:04 AM
    Nosnosna
    select age from table1 order by age desc limit 1

    What this does, piece by piece:

    select age from table1 : Basic query, will get the age for every entry in table1
    order by age: Sorts the results by age. Lowest is first by default
    desc : Changes the sort order to descending. This will make the results sorted with the highest age first
    limit 1: Will only return the first result after the sort.

    Note that you can then use this result to easily retrieve all entries that share that highest age using it as a subquery:

    select * from table1 where age = (select age from table1 order by age desc limit 1)
  • May 31, 2007, 09:06 AM
    jstrike
    Use the max aggregate function...
    Select max(age) from table1

  • All times are GMT -7. The time now is 01:51 PM.