fix incorrect sql for search/sort