applying limit first and then sorting.