Hi to all, I create the following table.

create table man(id integer, name varchar(20), city varchar(20), age integer)
I want the age, maximum age of person. So, I ran following query,

select name, max(age) from man group by name;
It shows name of all person in ascending order with their age. What is going wrong?

Thanks & regards,
Pooja.

you need to select just the age, the fact that you are grouping by name, the only time it will give you the maximum age is if you have two records example
Paul 20 and Paul 40 then that will return Paul 40. but for each name will return his age.

if you want just the oldest name and age try something like

SELECT TOP 1 name, age
FROM         man
ORDER BY age DESC

you should consider that could be more than one person with the same oldest age.

hope that helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.