多个表的多个列联接到同一个表



我有一个查询。

我在mysql数据库中有3个表。

我想用这些规则连接我的表,多个表的,多列连接到同一个表的一列。

MySQL示例如下。提前谢谢。

SELECT
s.*,e.* 
, m1.m_id AS 'mid'
, m1.m_name AS 'mname' 
, m2.m_id AS 'bid'
, m2.m_name AS 'bname'
, e1.e_id AS 'tid'
, e1.e_name AS 'tname'
, e2.e_id AS 'topid'
, e2.e_name AS 'topname'
FROM s s,e e
INNER JOIN m m1
ON s.s_m_id = m1.m_id
INNER JOIN m m2
ON s.s_b_id = m2.m_id
INNER JOIN e e1
ON s.s_t_id = e1.e_id
INNER JOIN e e2
ON s.s_t_t_id = e2.e_id
WHERE s_id =1
$this->db->select("s.*,e.* 
, m1.m_id AS 'mid'
, m1.m_name AS 'mname' 
, m2.m_id AS 'bid'
, m2.m_name AS 'bname'
, e1.e_id AS 'tid'
, e1.e_name AS 'tname'
, e2.e_id AS 'topid'
, e2.e_name AS 'topname'");
$this->db->from("FROM s");
$this->db->join("m m1
s.s_m_id = m1.m_id","inner");
$this->db->join("m m2
s.s_b_id = m2.m_id","inner");
$this->db->join("e e1
s.s_t_id = e1.e_id","inner");
$this->db->join(" e e2
s.s_t_t_id = e2.e_id","inner");
$this->db->where('s_id','1');
$this->db->get();

您的代码不工作吗?尝试删除上的"FROM">

$this->db->from("FROM s");

相关内容

  • 没有找到相关文章

最新更新