View Full Version : adding values of a single column
utinaeniduin
01-17-2007, 06:00 AM
how can i add all the values of one column of the table to get a total?
koyama
01-17-2007, 10:32 AM
SELECT SUM(myColumn) FROM myTable WHERE 1
guelphdad
01-17-2007, 01:54 PM
Note that the WHERE 1 is not necessary.
utinaeniduin
01-17-2007, 05:44 PM
cool. now how do i store that sum in a variable?
koyama
01-17-2007, 06:02 PM
I guess you are using php?
$sql = "SELECT SUM(myColumn) FROM myTable";
$result = mysql_query($sql);
list($sum) = mysql_fetch_row($result); // now $sum = 'the sum'
vBulletin® v3.8.2, Copyright ©2000-2009, Jelsoft Enterprises Ltd.