Limit SQL join when using CodeIgniter active record class
问题 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? 回答1: Add $this->db->limit(1); before calling $this->db->get('products p'); . See the docs at ellislab.com: search