[英]How to join three tables using Codeigniter if there is no common fields?
假设我的Mysql表是
表1-存款明细
id | deposit_type | 金额| deposit_master_id
1 | 固定| 100000 | 1个
表2-存款主
deposit_master_id | bank_id | branch_id
1 | 1 | 2
表3-银行总行
bank_id | 银行的名字
1 | 履行机构
我知道Codeigniter中的基本SQL Join操作,但我也做到了,但这是一个场景,这三个表没有通用字段,但我认为它们可以联接,但是我没有任何线索。 如何通过存款明细从银行管理员那里获得银行名称 ?
样本输出
id | 银行的名字
1 | 履行机构
//从表格中选择您想要的列
$this->db->select('*');
$this->db->from('Deposit Details dd');
$this->db->join(' Deposit Master dm', 'dd.deposit_master_id=dm.deposit_master_id', 'inner');
$this->db->join('Bank Master bm ', 'bm.bank_id =dm.bank_id', 'inner');
select d.id,bm.bank_name
from Deposit_Details d
inner join Deposit_Master dm on dm.deposit_master_id = d.deposit_master_id
inner join Bank_Master bm on bm.bank_id = dm.bank_id
$this->db->select('Deposit_Details.id,Bank_Master.bank_name');
$this->db->from('Deposit_Details');
$this->db->join('Deposit_Master', 'Deposit_Master.deposit_master_id = Deposit_Details.deposit_master_id');
$this->db->join('Bank_Master', 'Bank_Master.bank_id = Deposit_Master.bank_id');
$query = $this->db->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.