比较codeigniter中两个表的数据

时间:2013-05-23 19:31:00

标签: php mysql codeigniter phpmyadmin

我有两个表(评论和评估),我想在codeigniter中执行以下mySQL查询。 这是mySQL查询:

SELECT COUNT(DISTINCT source) AS NumberOfEvaluations 
FROM COMMENT , EVALUATION
WHERE evaluation_id = EVALUATION.id AND EVALUATION.department_id = '$department_id' ;

这就是我达到的距离越近:

$this->db->select('count(DISTINCT(source))');  
$this->db->from('comment','evaluation');  

$this->db->where();  

$query=$this->db->get();  
return $query->num_rows();  

我的问题是我应该在codeigniter中查看where子句?

1 个答案:

答案 0 :(得分:0)

尝试运行此代码:

$this->db->select('count(DISTINCT(source))');  
$this->db->from('comment c','evaluation e');  

$this->db->where('c.evaluation_id','e.id');
$this->db->where('e.department_id', $department_id);