duan0417 2018-04-11 02:59
浏览 80
已采纳

LEFT JOIN CODEIGNITER中的错误“不唯一的表/别名”

I've a got a error says Not unique table/alias: 'pcdom_missionaries'

here's my sample code in model

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

An error appears in the image

Not unique table/alias: 'pcdom_missionaries'

Can Anyone had the ideas? thanks in advance

  • 写回答

1条回答 默认 最新

  • doupacan2098 2018-04-11 03:10
    关注

    Since you are doing self joins on pcdom_missionaries you need to alias pcdom_missionaries table in each separate joins to make it look unique to SQL so it can use it in joins without confusion

    ->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')
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?