我想将表 a 联接到表 b 或表 c
我有数据库
table a
id
email
table b
id
name
admin
table c
id
name
user
//ilustration
table b.id = 01-admin
table c.id = 01-user
如果表a.id = 01-user,我可以从表c获取数据 并且数据将在表 a 上循环
我尝试示例
$this->db->select('*');
$this->db->from('a');
$this->db->join('b', 'a.id = b.id');
//OR
$this->db->join('c', 'a.id = c.id');
$query = $this->db->get();
return $query;
请帮助我,
如何编写带有条件 OR 的 JOIN 代码
最佳答案
可能使用左外连接:
$this->db->select('*');
$this->db->from('a');
$this->db->join('b', 'a.id = b.id', 'LEFT OUTER');
$this->db->join('c', 'a.id = c.id' 'LEFT OUTER');
$query = $this->db->get();
return $query;
只有匹配时,您才会从 B 或 C 获得东西。
关于php - 使用 codeigniter 通过 OR 进行内连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42764197/