Peter South wrote:
Ok here is what I'm trying to do.
Table 1 Table 2
Table 3
Column1(id) Column2 (score) Column1(id) Column2(score)Column1(id) Column2(name)
1
[snip]
[snip]
Can anyone tell me how to add up values in different tables? For example
Table1.Column1 + Table2.Column2 + Table1.Column3 Where id(row) =3D n
[/snip]
SELECT t1.c1 + t2.c2 + t3.c3 FROM table WHERE id =3D n
The above doesn't work I'm afraid.
[/snip]
Don't be afraid, you must join th
[snip]
Can anyone tell me how to add up values in different tables? For example
Table1.Column1 + Table2.Column2 + Table1.Column3 Where id(row) =3D n
[/snip]
SELECT t1.c1 + t2.c2 + t3.c3 FROM table WHERE id =3D n
The above doesn't work I'm afraid.
[/snip]
Don't be afraid, you must join the tables
How about:
select sum(t1.column1 + t2.column2 +t3.column3) as Columnsum
from
Table1 t1
inner join Table2 t2 on t1.id=t2.id
inner join Table3 t3 on t2.id=t3.id
where t1.id=n
group by t1.id
This is a rough cut that assumes the id value in the join exists in all
three tables. If it's missing in
[snip]
Can anyone tell me how to add up values in different tables? For example
Table1.Column1 + Table2.Column2 + Table1.Column3 Where id(row) = n
[/snip]
SELECT t1.c1 + t2.c2 + t3.c3 FROM table WHERE id = n
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscr