是否可以纠正此查询
`$sql = '
SELECT *
FROM employers
LEFT JOIN jobwall ON jobwall.employers_employer_id = employers.employer_id
WHERE employers.employer_id
IN (SELECT employers_employer_id FROM jobwall)
';
$this->db->query($sql);`
作为codeigniter中的活动记录
答案 0 :(得分:2)
我同意Joe Stefanelli,LEFT JOIN和WHERE IN子查询对于普通连接是不必要的。以下应该做你想要的:
$this->db->join('jobwall'
, 'jobwall.employers_employer_id = employers.employer_id');
$this->db->get('employers');
只有当你想让所有雇主都知道他们是否在工作区表中时,你才会使用LEFT JOIN。
答案 1 :(得分:1)
$this->db->select('employers_employer_id');
$this->db->from('jobwall');
$subquery = $this->db->_compile_select();
$this->db->_reset_select();
$subquery = str_replace("\n"," ",$subquery);
$this->db->where_in('tag_page_id', $subquery, false); //false=if no escape for subquery
$this->db->join('jobwall', 'jobwall.employers_employer_id = employers.employer_id','left');
$this->db->get('employers');