我发现错误 Not unique table/alias: 'pcdom_missionaries'
这是我在模型中的示例代码
public function samplemethodname()
{
$this->db->select('companionship_id, missionary_one_id, missionary_two_id, missionary_three_id, pcdom_companionship.zone_id AS pczone_id, pcdom_companionship.district_id AS pcdistrict_id,
pcdom_companionship.area_id AS pcarea_id, assignment, zone_name, pcdom_zone.zone_id AS pz_zone_id, district_name, pcdom_district.district_id AS pd_district_id, area_name, pcdom_area.area_id AS pa_area_id, missionary_id, missionaries_name')
->from('pcdom_companionship')
->join('pcdom_missionaries','pcdom_missionaries.missionary_id = pcdom_companionship.missionary_one_id','left')
->join('pcdom_missionaries','pcdom_missionaries.missionary_id = pcdom_companionship.missionary_two_id','left')
->join('pcdom_missionaries','pcdom_missionaries.missionary_id = pcdom_companionship.missionary_three_id','left')
->join('pcdom_zone','pcdom_zone.zone_id = pcdom_companionship.zone_id','left')
->join('pcdom_district','pcdom_district.district_id = pcdom_companionship.district_id','left')
->join('pcdom_area','pcdom_area.area_id = pcdom_companionship.area_id','left');
$sql = $this->db->get();
if($sql && $sql->num_rows() > 0 )
return $sql->result();
else
return;
}
图像中出现错误
任何人都可以有这些想法吗? 提前谢谢
答案 0 :(得分:1)
由于您在pcdom_missionaries
上进行自联接,因此需要在每个单独的连接中使用别名pcdom_missionaries
表,使其看起来对SQL是唯一的,这样它就可以在连接中使用它而不会产生混淆
->join('pcdom_missionaries as pcdom_m1','pcdom_m1.missionary_id = pcdom_companionship.missionary_one_id','left')
->join('pcdom_missionaries as pcdom_m2','pcdom_m2.missionary_id = pcdom_companionship.missionary_two_id','left')
->join('pcdom_missionaries as pcdom_m3','pcdom_m3.missionary_id = pcdom_companionship.missionary_three_id','left')