2017-01-26 88 views
0

聯接如何笨如何編寫MySQL查詢像笨

$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; 

回答

0

像下面寫像一個聯接條件查詢該this.first得到驗證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); 
+0

該查詢是從SQL禁令性能我好還是你.. –

+0

如果你直接使用'$這個 - > DB->查詢()'它不會阻止。如上所述嘗試。 –

+0

我試過$ verificationIds = $ this-> db-> get('table_invistigate') - > result_array();它正在返回顯示數據庫錯誤的數組作爲不在(數組,數組)中的位置 –

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();