如果我删除第二个连接查询,它的工作原理,但不起作用!
错误:列参考"类别"模棱两可的第1行:...", " prefix_product"" full_desc" as" description"," category" ... ^
SELECT "prefix_product"."id" as "product_id",
"prefix_product"."title" as "name",
"prefix_product"."short_desc" as "briefDescription",
"prefix_product"."full_desc" as "description",
"category" as "productCategory"
FROM "prefix_product"
JOIN "prefix_category"
ON "prefix_product"."category"="prefix_category"."id"
JOIN "prefix_category_attribs"
ON "prefix_product"."category"="prefix_category"."parent"
WHERE "vendor" = '8'
我使用codeigniter3和postgresql,在codeigniter中,我有:
$this->db->select(['prefix_product.id as product_id', 'prefix_product.title as name', 'prefix_product.short_desc as briefDescription', 'prefix_product.full_desc as description','category as productCategory']);
$this->db->where('vendor',$vendorId);
$this->db->from($this->tblName);
$this->db->join('prefix_category','prefix_product.category=prefix_category.id');
$this->db->join('prefix_category_attribs','prefix_product.category=prefix_category.parent');
$queryResult =$this->db->get()->result();
感谢
答案 0 :(得分:1)
似乎有多个表具有相同的列名,即category
。因此,您需要在category
子句中为列SELECT
添加前缀,以便明确指定列所属的表:
"prefix_product"."category" as "productCategory"