0
       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'不明确”。关于如何解决这个问题有什么想法吗?

4

3 回答 3

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.IDparent.ID

于 2013-05-20T08:00:08.680 回答
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
于 2013-05-20T08:00:53.553 回答
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)。

于 2013-05-20T07:59:59.277 回答