What I learned today
Useful SQLite tip: any time you useĀ 

"select a, b, min(c) from x group by a" SQLite will pick the row that contains that minimum c value and use that as the source of the other columns - see "Bare columns in aggregate queries" in the docs

https://www.sqlite.org/lang_select.html#bareagg