fix SQL error if id is the sort type