1
Hello, I am working with MYSQL, I wonder if I can use the result of a function in Where, calling by alias.
today I have to repeat the code, in case that GEO function
SELECT *,round(geo(-46.000000,-23.000000,latitude,longitude),3) AS distancia
FROM view_empresas_pins
where round(geo(-46.000000,-23.000000,latitude,longitude),3) <= 7
I’d like to do something like this:
SELECT *,round(geo(-46.000000,-23.000000,latitude,longitude),3) AS distancia
FROM view_empresas_pins where distancia <= 7
where the result of the GEO function is used in Where, without I have to call again.
You could put one more SELECT around that by creating a subquerie, that’s another way of doing it, but that slows down performance because it generates a temporary table. I advise repeating the expression.
– Rafael Salomão