sql way
slightly better version
it's already sorted