Fix for #174 - Incorrect SQL generated with syntax error at the "order by" clause