In mysql is there a way where I can re-use the result of a subquery inside the main query?
select
(select resultado from tabela limit 1) as resultado_subquery,
(resultado_subquery * outra_coluna) as teste
from tabela
In mysql is there a way where I can re-use the result of a subquery inside the main query?
select
(select resultado from tabela limit 1) as resultado_subquery,
(resultado_subquery * outra_coluna) as teste
from tabela
You can do something like the example below:
select
subquery.resultado,
(subquery.resultado * outra_coluna) as teste
from tabela
left join (select codigo, resultado from tabela limit 1) as subquery on (tabela.codigo = subquery.codigo)
In short, you can by the subquery in LEFT JOIN as a temporary table, but it will have to relate to some main SQL key, for example the CODE column is the key.