SQL Query to retrieve highest item up to a point in a group

Posted by James on Stack Overflow See other posts from Stack Overflow or by James
Published on 2010-03-11T00:11:30Z Indexed on 2010/03/11 5:18 UTC
Read the original article Hit count: 466

Filed under:
|

The best way of describing this is I have a table of people with their names and ages. Assume that people with the same surname are from the same family. I need a query in oracle which will retrieve a list of the oldest person in each family, but not older than a certain age.

Table: person

name      surname         age
===============================
James     Smith           23
Sarah     Powell          17
Barry     Smith           31
Mark      Smith           35
Mary      Smith           18
Bob       Powell          30

How do I retrieve the oldest person in each family under 30?

Results I'm after

name      surname         age
===============================
James     Smith           23
Sarah     Powell          17

© Stack Overflow or respective owner

Related posts about Oracle

Related posts about sql