title: Best Query to retrieve data from two large tables in Codeigniter
body: <p>I am working on a laundry management system and want to retrieve customer order details with customer name from two tables having 25000+ rows of data. My code is working fine but using joins its taking too long to fetch the result. Kindly help me optimize the query. thanks
  here goes my code that works fine buts takes more than a minute to return the data and almost crashes most of the time...</p>
  
  <pre><code>$this-&gt;db-&gt;select('users.first_name,customer_order.auto_id, customer_order.invoice_no, customer_order.order_date, customer_order.order_place_from, customer_order.customer_id, customer_order.total_qty, customer_order.discount, customer_order.disc_amt, customer_order.total_paid, customer_order.total_balance, customer_order.delivery_date, customer_order.amt_paidby, customer_order.order_status, customer_order.mode_of_payment_adv, customer_order.advance_paid, customer_order.mode_of_payment_bal, customer_order.balance_paid_date');
  $this-&gt;db-&gt;from('customer_order');
  $this-&gt;db-&gt;join('users', 'customer_order.customer_id=users.id');
  $this-&gt;db-&gt;order_by("auto_id","desc");
  $data['invoiceorder'] = $this-&gt;db-&gt;get()-&gt;result();
  </code></pre>
  
  <p>Limiting the record gives accurate timing but I need to fetch all records</p>