It needs to only affect finished attempts, and the wording needs to be modified to make it clear that is what it does.
We were using ORDER BY id even though there was a perfectly good attempt column to order the attempts by one user at one quiz. Also, Oracle was complaining: Debug info: ORA-01799: a column may not be outer-joined to a subquery
Follow-on from MDL-37684.