How to get "unique" rows in a Google Sheets QUERY(), ignoring a specific column when factoring uniqueness?
02:09 11 May 2026

I have data that looks like this, a list of trips where each trip is a 6-tuple of date, system, line, bus route, distance, and mode:

original data

I want to get the top 10 longest trips, so I do a query and order it by the descending order on column E:

=QUERY('Mileage 2026'!A:E, "select * where E is not null order by E desc limit 10")

However, this leads to rows that have the same system, line, bus route, and distance columns that only differ on the date column (the MNR-New Haven, Amtrak-Hartford, and NJT Rail-NEC trips):

top ten length, but with duplicates excepting date

I have tried to use SORTN, but it gives the earliest trip of that length instead:

=SORTN('Mileage 2026'!A2:E, 10, 2, 5,FALSE)

top ten length from SORTN, but Amtrak-New Haven is showing the first trip rather than latest

I want to show only the latest trips that are the longest, and keep the date column. How can I do this in Google Sheets query language?

google-sheets google-sheets-formula