Add missing order by logic to Build Query.