Fixed sorting

Sorting wasn't applied to the sql query