Ask Experts Questions for FREE Help !
Ask
    alfredlionel's Avatar
    alfredlionel Posts: 9, Reputation: 1
    New Member
     
    #1

    May 1, 2007, 12:08 PM
    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
    Nosnosna's Avatar
    Nosnosna Posts: 434, Reputation: 103
    Full Member
     
    #2

    May 5, 2007, 08:04 AM
    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)
    jstrike's Avatar
    jstrike Posts: 418, Reputation: 44
    Full Member
     
    #3

    May 31, 2007, 09:06 AM
    Use the max aggregate function...
    Select max(age) from table1

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Sql and vb [ 2 Answers ]

How can I link sql and visual basic to work together?

My sql [ 1 Answers ]

How can I create user name and password In Ms Sql (using query analyzer) as we do in Oracle.

Sql Vs. Oracle [ 1 Answers ]

Sir, Would u explain the differences between the oracle and sql, as while working with oracle v r using sql and then executing our command.

Why 6" above flood rim of highest fixture? [ 7 Answers ]

hey tom, how goes it? I just completed my cast to pvc conversion of my attic reomodel. I did revent all my existing fixtures up so that they are 6" above the flood rim of my 2nd floor lav. My question is why? :confused: I can't seem to come up with a decent reason. Could you enlighten me? Also,...

SQL Server [ 1 Answers ]

Does anyone know where I can find a bit of a tutorial on the web about creating a database in SQL server 2000?


View more questions Search