如何以codeigniter格式编写此查询?
SELECT rights_management.id, rights_management.tab_name FROM rights_management
WHERE rights_management.id NOT IN (SELECT r_m.tabid FROM r_m)
感谢您的帮助。 。
答案 0 :(得分:2)
您可以使用where
子句
$this->db->select('rights_management.id, rights_management.tab_name');
$this->db->from('rights_management');
$this->db->where('`rights_management.id` NOT IN (SELECT r_m.tabid FROM `r_m`)', NULL, FALSE);
答案 1 :(得分:1)
首先,您必须从表r_m中选择r_m.tabid并将其存储在数组中。
$this->db->select('r_m.tabid');
$this->db->from('r_m');
$query = $this->db->get();
$alb = $query->result_array();
将其设为数组
foreach($alb as $rs){
$not_need[]=$rs['tabid'];
}
之后使用where_not_in。
触发一般活动类 $this->db->where_not_in('rights_management.id', $not_need);
$this->db->select('rights_management.id, rights_management.tab_name');
$this->db->from('rights_management');
$result= $this->db->get();
答案 2 :(得分:0)
$this->db->query('SELECT rights_management.id, rights_management.tab_name FROM rights_management WHERE rights_management.id NOT IN (SELECT r_m.tabid FROM r_m)');