Fix nearest retrieval: apply ORDER to SQL query.