Question: I'm getting a product listing. Each product may have 1 or more image, I only want to return the first image.

```
$this->db->select('p.product_id, p.product_name i.img_name, i.img_ext');    
$this->db->join('products_images i', 'i.product_id = p.product_id', 'left');
$query = $this->db->get('products p');

```

Is there anyway to limit the db->join to 1 record using the CI active record class?

Answer: 
Add `$this->db->limit(1);` before calling `$this->db->get('products p');`. See the docs at [ellislab.com](http://ellislab.com/codeigniter/user-guide/database/active_record.html): search the page for **limit**.

EDIT: I misread the fact that you were trying to apply the LIMIT to the internal JOIN statement. 

No. Since you can not do a LIMIT on an internal JOIN statement in regular SQL you can not do it with Code Igniter's ActiveRecord class.
Had this issue too the way I solved it was iterating over the results and removing the current object if the product\_id had existed in a previous one. Create a array, push the product\_id's to it while checking if they are repeats. 

```
$product_array = array();
$i = 0;

foreach($result as $r){

    if(in_array($r->product_id,$product_array)){
        unset($result[$i]);
    }else{
        array_push($product_array,$r->product_id);
    }
    $i++;

} 

$result = array_values($result); //re-index result array

```

Now $result is what we want