simple SQL questions

SONYFX

Senior member
May 14, 2003
403
0
0

If I have a table like below with three columns:

ID Total1 Total2
---------------------------------
1 10 20
2 15 5


How do I write a SQL query so that it returns (add up columns in every row):


ID Total
-----------------------
1 30
2 20
 

WannaFly

Platinum Member
Jan 14, 2003
2,811
1
0
if the total columns are not char:
select ID, Total1+Total2 as Total from <tablename>

select ID, sum(total1, total2) as Total from <tablename>

Those work in MSSQL, probably very similar in mysql.

 

SONYFX

Senior member
May 14, 2003
403
0
0
Originally posted by: WannaFly
if the total columns are not char:
select ID, Total1+Total2 as Total from <tablename>

select ID, sum(total1, total2) as Total from <tablename>

Those work in MSSQL, probably very similar in mysql.


I tried and it gives me an error: "invalid number of arguments"
 

BoberFett

Lifer
Oct 9, 1999
37,562
9
81
That first statement Wannafly gave was straight ANSI SQL, that should work in just about any database. Give us your exact query, you probably have an extra comma somewhere.