我有一个内连接查询,如下所示,
SELECT * FROM shop_offer so INNER JOIN shop s ON s.shop_id = so.shop_id INNER JOIN city c ON c.city_id = s.city_id INNER JOIN locality l ON l.locality_id = s.locality_id INNER JOIN category ca ON ca.category_id = s.category_id WHERE so.offer_discount >= 10 AND so.publish = 1
在phpmyadmin中执行上述查询时,结果只显示预期的一行。
但是当我在codeigniter中尝试此查询时,结果显示3行。我的codeigniter代码是,
$this->db->select('*');
$this->db->from('shop_offer as so');
$this->db->join('shop as s', 's.shop_id = so.shop_id');
$this->db->join('city as c', 'c.city_id = s.city_id');
$this->db->join('locality as l', 'l.locality_id = s.locality_id');
$this->db->join('category as ca', 'ca.category_id = s.category_id');
$this->db->where(array('so.offer_discount >=' => 10, 'so.publish' => 1));
$query = $this->db->get();
codeigniter代码有什么问题。我是codeigniter的新手。有没有办法解决这个错误。
答案 0 :(得分:1)
您也可以尝试运行这样的查询,
$this->db->query("SELECT * FROM shop_offer so
INNER JOIN shop s ON s.shop_id = so.shop_id
INNER JOIN city c ON c.city_id = s.city_id
INNER JOIN locality l ON l.locality_id = s.locality_id
INNER JOIN category ca ON ca.category_id = s.category_id
WHERE so.offer_discount >= 10 AND so.publish = 1");