你可以這樣做,
方法1:
$this->db->select('name')->from('users');
$this->db->where('Id IN (SELECT userId FROM `Trustmembers`)', NULL, FALSE);
$result = $this->db->get();
NULL, false
將用於無法逃避的查詢作爲默認。
方法2
$this->db->select('name')->from('users');
$this->db->where_in('Id', 'SELECT userId FROM `Trustmembers`');
$result = $this->db->get();
方法3:subquery library
$this->db->select('name')->from('users');
$subquery = $this->subquery->start_subquery('where_in');
$subquery->select('userId')->from('Trustmembers');
$this->subquery->end_subquery('Id', FALSE);
$result = $this->db->get();
我希望這將有助於。
反駁此鏈接:http://stackoverflow.com/questions/35405635/convert-simple-select-statement-from-php-to-mvc-php –