Kahuki Webmaster Forum and Discussion Community  

Go Back   Kahuki Webmaster Forum and Discussion Community > Website Development & Management > Programming > PHP



Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-07-2006, 06:11 PM
Violent770's Avatar
Member
 
Join Date: Aug 2006
Posts: 58
Violent770 is on a distinguished road
MySQL, Can you get the sum of two columns in the same row?

I have two columns in my table with numeric values. The table has over 1000 rows. I want to add the two number together per row. Do I need to set a varible?

Reply With Quote
  #2 (permalink)  
Old 03-07-2006, 06:29 PM
Darnok's Avatar
Rookie
 
Join Date: Jan 2006
Posts: 7
Darnok is on a distinguished road
Nope...try this...
select sum(field_A + field_B) from table_name

Reply With Quote
  #3 (permalink)  
Old 03-07-2006, 06:35 PM
Rookie
 
Join Date: Nov 2005
Posts: 7
ladyluck is on a distinguished road
You will want to alias the result so you can display it:

SELECT value1, value2, SUM(value1, value2) AS totalvalue FROM yourtable

Sample output:
============|===========|==================
value1 |value2 |totalvalue
============|===========|==================
5 |6 |11
10 |2 |12
4 |1 |5
9 |302 |311
===========================================
4 rows returned
===========================================

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to Update MYSQL database table based on mysql query array? blackfox PHP 2 03-30-2007 02:11 AM
how to connect mysql using php 5?mysql is not activated by default...so error message is shown....what to do? Jason M PHP 2 03-15-2007 06:25 PM
MySQL columns and an upper limit.? kreak PHP 2 01-15-2007 05:22 PM
MySQL & MySQL Server Removal Help Needed Please? I feel so dumb to be this damn smart!? blackfox PHP 1 11-26-2006 06:27 PM
Zulu Pad "PHP MYSQL program exactly like ZuluPad that you can put up on a web server and sync to MYSQL? baggiho PHP 1 10-10-2006 07:24 AM


All times are GMT. The time now is 10:06 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0