Optimizing sql for order list.