order_by from a query makes unrelated query fail
<p>I'm facing a problem where I cannot use <code>order_by</code> in one of my MYSQL query as it makes another one not working. What I do not understand is that <strong>both queries are unrelated and changing the first one shouldn't affect the second one</strong>.
Can you see why <code>order_by</code> is affecting <code>list_all_resorts</code>?</p>
<p>I've added some comments (//) to the intesresting parts.</p>
<pre><code>$shift_level = $this-&gt;shift_previous_day($list_all_resorts, 'level');

protected function shift_previous_day($list_all_resorts, $type) {
    foreach ($list_all_resorts-&gt;result() as $list_all_resorts_Array){
        $shift_DB = $this-&gt;shift_previous_day_DB($list_all_resorts_Array-&gt;id_resort, $type);
    }
    echo $shift_previous_day_DB;
} 
    
protected function shift_previous_day_DB($id_resort, $type){
    $this-&gt;db-&gt;trans_start();
    $this-&gt;db-&gt;set($type.'_d134', $type.'_d133', FALSE);
    $this-&gt;db-&gt;set($type.'_d1', $type.'_d0', FALSE);
    $this-&gt;db-&gt;set($type.'_d0', '0', FALSE);
    $this-&gt;db-&gt;where('id_resort', $id_resort);
    $this-&gt;db-&gt;update('game_resort_'.$type); 
    $this-&gt;db-&gt;order_by('season', 'DESC');  // If I remove this line there is no error thrown
    $this-&gt;db-&gt;limit('1'); 
    $this-&gt;db-&gt;trans_complete();
    if ($this-&gt;db-&gt;trans_status() === FALSE){
        return log_message();
    }
    else {
        $result = 'all OK';
        return $result;
    }  
}

$add_cash_to_history = $this-&gt;add_todays_stat_to_history('cash'); 
 
//This is where list_all_resorts will fail. Before that it works fine
protected function add_todays_stat_to_history($data_type) {
    $info_message = '';
    $list_all_resorts = $this-&gt;list_all_resorts();  // The is where list_all_resorts is called
    foreach ($list_all_resorts-&gt;result() as $row_list_all_resorts){
        //do some stuff
    }
    return $info_message;
}
    
protected function list_all_resorts(){  
    $this-&gt;db-&gt;select('id_resort'); // This is where the error points to
    $this-&gt;db-&gt;from('game_resorts');
    return $this-&gt;db-&gt;get();
}
</code></pre>
<p>The error I get is:</p>
<blockquote>
<p>A Database Error Occurred Error Number: 1054 Unknown column 'season'</p>
<p>in 'order clause' SELECT <code>game_resorts</code>.<code>id_resort</code> FROM</p>
<p><code>game_resorts</code> ORDER BY <code>season</code> DESC LIMIT 1</p>
</blockquote>
<p>Update:</p>
<pre><code>describe game_resorts:
id_resort   int(11) NO  PRI     auto_increment  
resort_name varchar(45) NO              
resort_country  varchar(45) YES             
resort_description  varchar(256)    YES             
id_player   int(11) YES MUL 

describe `game_resort_cash`:
id  int(11) NO  PRI         
id_resort   int(11) NO  MUL         
season  int(3)  NO      1       
cash_d0 int(11) YES             
cash_d1 int(11) YES                         
cash_d134   int(11) YES 

        
    
</code></pre>