added order by to sql generation