rewrote sqlquery.orderbyfirst and added tests