had order_by clause in the wrong part of the query