简体   繁体   中英

Join same table and columns twice

I've made 2 tables. One with assigned users to works (called employers):

桌子商店_雇主

...and the second with users:

表用户

I want to get user name and surname from users by appealing to column se_u_id in shops_employers , and again name and surname by appealing to column se_so_add_u_id in shops_employers . Here is code that I wrote:

$this->db->from('shops_employers as se');
$this->db->where('se_s_id', $shopID);
$this->db->where('se_accepted', 1);
$this->db->where('se_active', 1);
$this->db->join('users as u', 'se.se_u_id = u.u_id');
return $this->db->get()->result();

But I don't have any idea what to do next.

Try:

$this->db->from('shops_employers se');
$this->db->where('se.se_s_id', $shopID);
$this->db->where('se.se_accepted', 1);
$this->db->where('se.se_active', 1);
$this->db->join('users u', 'se.se_u_id = u.u_id', 'left');
return $this->db->get()->result();

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