user225269 user225269 - 1 year ago 108
SQL Question

How to use alias as field in mysql

I'm trying to do something like this. But I get an unknown column error:

SELECT SUM(field1 + field2) AS col1, col1 + field3 AS col3 from core

Basically, I want to just use the alias so that I won't need to perform the operations performed earlier. Is this possible in mysql?

Answer Source

Consider using a subquery, like:

,      col1 + field3 AS col3 
FROM   (
       SELECT  field1 + field2 as col1
       ,       field3
       from    core
       ) as SubQueryAlias
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download