alfredlionel
May 1, 2007, 12:08 PM
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
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
May 31, 2007, 09:06 AM
Use the max aggregate function...
Select max(age) from table1