Updating the query to sort by checked