...

View Full Version : SELECT alias question



Jak-S
08-23-2006, 05:45 PM
I have a question regarding the mysql SELECT statement. Is it possible to use an alias in the expression for another alias, for example:


SELECT net,
tax_rate,
net / tax_rate AS tax,
net + tax AS gross
FROM items

But that dosent work, mysql dosent allow an alias in the SELECT statement (says it cant find a field called tax), which is kind of annoying as it means i have to duplicate all my calculations like this:


SELECT net,
tax_rate,
net / tax_rate AS tax,
net + (net / tax_rate) AS gross
FROM items

This might not seem like a big deal in this query, but i have some other far more complicated queries where its just a pain. Is there any way to do this, it seems like it should be possible.

Thanks,
Jack

Beagle
08-24-2006, 04:29 PM
While I understand why you might want to do this, SQL is usually the ~wrong~ place to be doing calculations, especially in a high load situation. The DB has limited resources and needs them all to serve data faster. Also, by adding columns to the returned row, your adding more data that needs to be sent over the tubes, when instead you could be offloading the calculation load to your application and save on both processing time on the DB and on data transfer, which reduces the amount of work you dump on the DB.

And we all know that RDBMSs are not trucks. You can't dump on them.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum