Ensure that database results are sorted in the intended order