简体   繁体   中英

MySql Join in two tables using two different join statement in codeigniter

Whether the following join is valid in MySQL or not

$this->db->select('A.plan_prepared_by,A.approval_date, U.display_name');
$this->db->from('A');
$this->db->where('plan_id', $planid );
$this->db->join('U','U.id=A.approval_user_id','left');
$this->db->join('U','U.username =A.plan_prepared_by','left');

You can try it like this by putting aliases

$select =   array(
                    'A.plan_prepared_by',
                    'A.approval_date',
                    'UL.display_name'
);
$where  =   array(
                    'plan_id'   =>  $planid
);

$this->db->select($select);
$this->db->from('A');
$this->db->where($where);
$this->db->join('U AS UL','UL.id = A.approval_user_id','left');
$this->db->join('U AS UR','UR.username = A.plan_prepared_by','left');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM