correct sort order for queries