process sorting query