如何编写mysql查询就像在codeigniter中加入一样

时间:2017-01-26 04:22:59

标签: codeigniter

如何在codeigniter中将此查询写为连接条件

$query=$this->db->query("select TypeID,verification_type from table_verify where TypeID not in(select verificationId from table_invistigate where Id=$id)");
          $result = $query->result();
        return $result;

2 个答案:

答案 0 :(得分:0)

像这样。首先获取验证ID数组,然后在$this->db->where_not_in()中使用此数组。

$this->db->select('verificationId');
$this->db->where('Id',$id);
$verificationIds = $this->db->get('table_invistigate')->result_array(); //array of   verificationIds 

foreach($verificationIds as $vid){
$ids[] = $vid['verificationId']; 
}


$this->db->select('TypeID,verification_type');
$this->db->where_not_in('TypeID',$ids);
$result = $this->db->get('table_verify')->result_array();
print_r($result);

答案 1 :(得分:0)

    $this->db->select('table_verify.*,table_invistigate.verificationId');
    $this->db->from('table_verify');
    $this->db->join('table_invistigate',
   'table_verify.verificationId=table_invistigate.verificationId ');
    $this->db->where('table_verify.id',$id);
    $query = $this->db->get();
    return $query->result();