-2

This question is for Oracle SQL DEV

What I am trying to accomplish is to pull the top record for each person (last name + First name + Dob), using their most recent travel date. To help illustrate my point, I included a screenshot of two individuals and their travel history. I want my query to pull only one record from each name + dob group using their most recent travel date.

I tried to use the row_number and partition but couldn't gain any traction. Can a more experienced developer/programmer help me?

enter image description here

Paul White
  • 94,921
  • 30
  • 437
  • 687
SQLPhan
  • 11
  • 1
  • 1

1 Answers1

1

Something like the following (untested) should work:

with partitions as (
  select
    x.*,
    row_number() over (partition by last_name, first_name, dob order by travel_date desc) as r
  from my_table as x
)
select *
from partitions
where r = 1;
Colin 't Hart
  • 9,455
  • 15
  • 36
  • 44