Justnew Posted November 22, 2003 Share Posted November 22, 2003 I am trying to add a value to an existing value in the coumn by using the select statement select tea, mango, pepper price + profit as price from products the profit have a default value of 200. when I run the query I only get the value of the profit Can someone help me out Quote Link to comment https://forums.phpfreaks.com/topic/1413-adding-the-values-of-two-columns-together/ Share on other sites More sharing options...
Kriek Posted November 22, 2003 Share Posted November 22, 2003 Method no.1 SELECT tea, mango, pepper, price + profit AS total FROM products Method no.2 SELECT tea, mango, pepper, (price + profit) AS total FROM products Quote Link to comment https://forums.phpfreaks.com/topic/1413-adding-the-values-of-two-columns-together/#findComment-4684 Share on other sites More sharing options...
Justnew Posted November 23, 2003 Author Share Posted November 23, 2003 Thank you for your reply I have tried the code but the price column becomes blank no values is desplayed under the column name Price Quote Link to comment https://forums.phpfreaks.com/topic/1413-adding-the-values-of-two-columns-together/#findComment-4689 Share on other sites More sharing options...
Kriek Posted November 23, 2003 Share Posted November 23, 2003 Justnew, if you utilized either of my previous examples, the price column individually is non-existent. This is due to the fact that we have combined the values of the price and profit columns and then proceeded to alias that sum as total with the AS keyword. I do not recommend aliasing two columns with an original column name. To clarify why your previous method did not work is because the AS keyword is optional when aliasing a SELECT expression. So by not separating the pepper and price columns with a single coma you effectively aliased the pepper, price, and profit columns as price. Quote Link to comment https://forums.phpfreaks.com/topic/1413-adding-the-values-of-two-columns-together/#findComment-4692 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.