2

i have a problem with a specific selection in a table. In would like to find all Persons grouped by Name with the max year. But I need also the other columns, for a later join, in the result set.

Furthermore, the id is unordered, so it can not be used in an aggregate function. The query should be database agnostic.

Here is the Table:

enter image description here

Here is the Result that I need:

enter image description here

2 Answers2

1

You can try below- using correlated subquery

select * from tablename a
where year = (select max(year) from tablename b a.name=b.name)
Fahmi
  • 37,315
  • 5
  • 22
  • 31
1
select x.* from tbl x
join (select name, max(year) max_year from tbl group by name) y
on x.name = y.name and x.year = y.max_year
Michael Buen
  • 38,643
  • 9
  • 94
  • 118