SELECT realestate.id,node.id,node.name
from realestate,
(SELECT
GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,id
FROM
address AS node JOIN address AS parent
ON node.lft BETWEEN parent.lft AND parent.rgt
WHERE node.lft >={$lft} and node.rgt <={$rgt}
GROUP BY node.name) as node
INNER JOIN users ON id_user = users.id
LEFT JOIN pic ON id_realestate = realestate.id
WHERE node.id = realestate.address_id
我尝试多次修改它,此错误消息不会消失“数据库查询失败:字段列表中的列'id'不明确”。有什么想法解决这个问题吗?
答案 0 :(得分:2)
问题在于子查询,
SELECT GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,
id -- <<== HERE (change to node.ID or parent.ID)
FROM address AS node
JOIN address AS parent
ON node.lft BETWEEN parent.lft AND parent.rg
您应指定ID
来自哪个表,因为node and parent
包含导致歧义的ID。它可以是node.ID
或parent.ID
答案 1 :(得分:2)
这是因为您在连接的查询中使用了id,所以它不明确,只需更改以避免错误
GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,node.id --here you need to specify that is from node
答案 2 :(得分:0)
改变这个:
GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,id
与
GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,node.id
您需要指定表的别名,因为mysql不知道用于获取id
列的表(假设两个表都有一个名为id
的列)。