Fixed some order by issues, but there is a framework issue (for Derby at least) when an order by column is not selected in a distinct query