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.
To expand on @Femi's answer:

There's no good way to limit the `JOIN`, and, in fact, you don't really want to. Assuming both `products_image.product_id` and `products.id` have indexes (and they absolutely should if you're going to join against them repeatedly) when the database engine does a join, it uses the indexes to determine what rows it needs to fetch. Then the engine uses the results to determine where on the disk to find the records it needs. If you 

You should be able to see the difference by running these SQL statements:

```
EXPLAIN 
SELECT p.product_id, p.product_name, i.img_name, i.img_ext
FROM products p
LEFT JOIN products_images i
    ON i.product_id = p.product_id

```

as opposed to:

```
EXPLAIN  
SELECT p.product_id, p.product_name, i.img_name, i.img_ext
FROM (SELECT product_id, product_name FROM products) p 
LEFT JOIN (SELECT img_name, img_ext FROM products_images) i
    ON i.product_id = p.product_id

```

The first query should have an index, the second one will not. There should be a performance difference if there's a significant number of rows the the DB.