[英]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.