I've upgraded from MySQL 5.5 to 5.7 and I have a query that no longer works. It's quite a big one but I've reduced it down to this - the query itself doesn't really make sense but demonstrates:
SELECT
id AS id2,
name,
SUM(id * (SELECT 10 FROM event WHERE event.product_id=id2 LIMIT 1))
FROM product
GROUP BY product.category_id
This works in 5.5 but not in 5.7 (I get [Err] 1054 - Unknown column 'id2' in 'where clause'). It works if I don't alias the column:
SELECT
id,
name,
SUM(id * (SELECT 10 FROM event WHERE event.product_id=product.id LIMIT 1))
FROM product
GROUP BY product.category_id
But in the real query it's quite a complicated expression so I want to alias it. It also works in 5.7 if I exclude the aggregate function:
SELECT
id,
name,
id * (SELECT 10 FROM event WHERE event.product_id=product.id LIMIT 1)
FROM product
GROUP BY product.category_id
I cant find anything in the docs that explains this discrepancy. I can rewrite the query but it will be a lot messier so I'm trying to figure out a way if I can re-enable this behaviour (note SQL_MODE is the same between versions).