Friday, March 23, 2012

how to get the highest row from the bunch of rows

hi...i just want to retrieve the highest row from the collection of
rows like...my table is:
name year
a 2008
a 2006
b 2007
b 2006
b 2005
c 2007
c 2004
I just need the latest year for all the names like:
name year
a 2008
b 2007
c 2007
THANKS..."sql_learner" <mailfrd@.gmail.com> wrote in message
news:eafce7c0-7c49-415e-b410-336593650ce2@.s8g2000prg.googlegroups.com...
> hi...i just want to retrieve the highest row from the collection of
> rows like...my table is:
> name year
> a 2008
> a 2006
> b 2007
> b 2006
> b 2005
> c 2007
> c 2004
> I just need the latest year for all the names like:
> name year
> a 2008
> b 2007
> c 2007
> THANKS...
SELECT name, MAX(year) year
FROM tbl
GROUP BY name;
--
David Portas|||sql_learner wrote:
> hi...i just want to retrieve the highest row from the collection of
> rows like...my table is:
> name year
> a 2008
> a 2006
> b 2007
> b 2006
> b 2005
> c 2007
> c 2004
> I just need the latest year for all the names like:
> name year
> a 2008
> b 2007
> c 2007
> THANKS...
SELECT name,MAX(year)
FROM tablename
GROUP BY name
... p
--
Posted via a free Usenet account from http://www.teranews.com

No comments:

Post a Comment