Implementing an order by clause that supports multiple queries.