Sorting redone with queries