I'm trying to work with a User-Defined variable, and it works as expected with MySQL 5.6.17, but gives the below error in MySQL 5.7.10.
I found a working example with this question, and it is failing with the same error.
I can't find any documentation or mention of the problem (rather broad terms to google), and am assuming that it is a MySQL configuration issue. Can anyone assist, or point me in the right direction.
Query: SELECT T2.* FROM ( SELECT @r AS _id, (SELECT @r := parent_id FROM pos_port_attachments WHERE id = _id) AS parent_id, @l := @l + ...
Error Code: 1054
Unknown column '_id' in 'where clause'
This is the SQL that I'm using
SELECT T2.*
FROM (
SELECT
@r AS _id,
(SELECT @r := parent_id FROM mytable WHERE id = _id) AS parent_id,
@l := @l + 1 AS lvl
FROM
(SELECT @r := 100001, @l := 0) vars,
pos_port_attachments m
WHERE @r <> 0) T1
JOIN mytable T2
ON T1._id = T2.id
ORDER BY T1.lvl DESC;