I facing with a strange situation with a sql query on mysql 5.1.41 environment on a Ubuntu machine.
The code follow
SELECT spedizione0_.idspedizione,
spedizione0_.*,
(
SELECT COUNT(n.idnegozio)
FROM negozio n
LEFT JOIN confezione c
ON n.idnegozio = c.idnegozio
AND c.idspedizione = spedizione0_.idspedizione
WHERE n.datainizio <= spedizione0_.dataspedizione
AND n.datafine >= spedizione0_.dataspedizione
OR c.idspedizione != 0
) AS formula5_
FROM orocashgenerico.spedizione spedizione0_
ORDER BY spedizione0_.dataspedizione DESC
In this case the error says : [Err] 1054 – Unknown column ‘spedizione0_.idspedizione’ in ‘on clause’
The only way to run this query is to change the .. on n.idnegozio=c.idnegozio and c.idspedizione=spedizione0_.idspedizione into on n.idnegozio=c.idnegozio and c.idspedizione=12
The most strange things for me is: if i move the and condition to the where clause the query run correctly, of course the results is not what I excepted.
My question is where is the problem?
Is something related to the MySQL version?
It’s because
spedizione0_is not found with the scope of your subquery. Try this one,