Is there a way to make reference to parts of a MySQL query within the same query?
For example:
SELECT 50000 AS starting_principle, .065*50000 AS interest,
principle + interest AS principle_plus_interest
The third column, principle_plus_interest
in the query set gives me an error. Is there a way to code this besides writing 50000 + .065*50000 AS principle_plus_interest
?
You cannot refer to aliases in the
select
list (or thewhere
clause, for that matter). One way around this is to use a subquery: