handling order by in queries