Order records explicitly for CSV export

I added explicit ORDER BY clauses to each SQL query.