getting unknown column in where clause
<p>am getting an error like</p>

<pre><code>Unknown column 'code' in 'where clause'
SELECT * FROM `payment` WHERE `code` = 'ORD00023'
</code></pre>

<p>even though i had used joined method for joining of payment table and services table.Here iam finding the solution of previous row value but its not getting.</p>

<p>this is my model </p>

<pre><code>public function order_balance($order_code)
{
$this-&gt;db-&gt;query("
SELECT p1.*
      , p2.balance AS previous_balance 
  FROM payment p1 
  JOIN payment p2 
    ON p1.order_id = p2.order_id + 1 
   AND p1.customer_id = p2.customer_id 
  LEFT 
  JOIN services s 
    ON p1.customer_id = s.customer_id 
 ORDER BY p1.id DESC
");
$query = $this-&gt;db-&gt;get_where('payment p1', array('code' =&gt; $order_code));
return $query;
}
</code></pre>

<p>this is my table payment</p>

<pre><code>id  order_id    customer_id  amount     actual_amount   paid_amount     balance     type
25  11            16                        100.00        50.00         50.00       Cash
26  12            16                        200.00        100.00        100.00      Cash
27  13            16                        150.00        100.00        50.00       Cash
28  14            16                        300.00        250.00        50.00       Cash
29  14            16                        170.00        100.00        70.00       Cash
30  15            16         100            170.00        70.00         100.00      Cash
31  16            16         400            500.00        300.00        200.00      Cash
</code></pre>

<p>this is table services</p>

<pre><code>id  code      customer_id   particulars     
11  ORD00011    16              phone   
12  ORD00012    16              gdf     
13  ORD00013    16              ghgfh   
14  ORD00014    16               tv     
15  ORD00015    16              ghfg    
16  ORD00016    16               tv     
17  ORD00017    16              gdfg    
18  ORD00018    16              desk    
19  ORD00019    16              gdf  
</code></pre>

<p>Here i have joined the payment table and services table but still not getting</p>

<p>see my table</p>

<pre><code>id  order_id    customer_id     amount  actual_amount   paid_amount     balance     type
50  31             16           650         750.00        250.00        500.00      Cash
51  1              16           100         600.00        300.00        300.00      Cash
52  2              16           100         400.00        200.00        200.00      Cash
53  3              16           800         1000.00       600.00        400.00      Cash
54  4              15           400         400.00        300.00        100.00      Cash
55  5              15           500         600.00        575.00        25.00       Cash
56  6              16           350         750.00        600.00        150.00      Cash
</code></pre>

<p>in this table the customer_id of <code>16</code> having the previous row value of balance 25 and am getting like this but i want the last customer_id <code>16</code> balance value as the previous customer_id <code>16</code> value.
for example my result should look like this</p>

<pre><code>id     order_id    customer_id   amount   actual_amount   paid_amount   balance     type
56       6         16          350          750.00        600.00        400.00      Cash
</code></pre>