Skip to the content

Empty-handed

Problem

The library wants to write to the members who don't have a single book at home right now and invite them back. Being empty-handed isn't the same as having returned something: Ann has returned two books and still has one out.

Show the member and the day of their latest return, in that order. Whoever has gone the longest without a book goes first.

What it has to return

These rows, in this order

memberlatest
Brian2026-01-04
Luke2026-01-15

This is what comes out with the data in the practice database this challenge uses. The column names don’t count, so name yours however you like: what counts is how many there are and the order they come in. Besides this one, the challenge has hidden tests with other data that are revealed when you submit your solution.

You start with this

SQL

SELECT member, returned
FROM loans
WHERE returned IS NOT NULL;
Solve this challenge

It opens in your browser, with the editor and the tests. This challenge is part of the full plan; the O(1) and O(log n) ones are free.

More O(n log n) challenges

See all challenges →