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

I tried to modify it several times and this error message would not disappear "Database query failed: Column 'id' in field list is ambiguous". is there any idea on how to solve this?

Sami
  • 477
  • 2
  • 5
  • 12

3 Answers3

2

The problem is on the subquery,

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

You should specify on what table does the ID come from since both node and parent contains ID which causes ambiguity. It could be node.ID or parent.ID

John Woo
  • 258,903
  • 69
  • 498
  • 492
2

this is because you are using id in your concatenated query, so it's ambiguous, simply change to avoid the error

GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,node.id --here you need to specify that is from node
Fabio
  • 23,183
  • 12
  • 55
  • 64
0

Change this:

GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,id

with

GROUP_CONCAT(parent.name_en ORDER BY parent.lft DESC) AS name,node.id

you need to specify the alias of the table because mysql doesn't know what table to use to get the id column (assuming that both tables have a column named id).

Stephan
  • 8,000
  • 3
  • 36
  • 42