![](/img/trans.png)
[英]join two tables in codeigniter and refere to two fields in the same table
[英]How to join two fields of a same table in CI?
我有一个名为“类别”的表。 它的结构是这样的:
id parent_id name
1 NULL Electronics
2 NULL Books
3 1 Mobile
4 2 Love Story
我想将“ parent_id”与“名称”字段一起加入。 如何在codeigniter中加入这两个字段?
这称为自连接
SELECT a.name + '-' + b.name
FROM categories a
INNER JOIN categories b
ON a.id = b.parentid
假设您正在使用CI的activerecord,请在此处查看
$this->db->select('*')
$this->db->from('categories c1')
$this->db->join('categories c2', 'c1.id = c2.parent_id');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.