Quote
The answer is:
SELECT @TTax:=SUM(TAX) FROM Invoices01;
update Invoices01 set TOTTAX = @TTax;
Sorry, but No; it absolutely is not (unless your table, Invoice01, only
ever contains just one row).
Relational Databases and their SQL are Set-Based. They find a set of rows to work with (FROM, JOIN, etc.) and then apply an action (SELECT, UPDATE, etc.) to
all of the rows in that set.
The SELECT ...
From
every single row in the table Invoices01, sum up the TAX field and assign the result into the variable, TTax.
So far, so good.
The UPDATE ...
In
every single row in the table Invoices01, update the field, TOTTAX, with the value of the variable, TTax.
Here's a "before" and "after" view of that table:
-- Before
select ...
from Invoice01 ;
+----+-----+--------+
| id | TAX | TOTTAX |
+----+-----+--------+
| 11 | 1.0 | 0.0 |
| 22 | 2.0 | 0.0 |
| 33 | 3.0 | 0.0 |
| 44 | 4.0 | 0.0 |
| 55 | 5.0 | 0.0 |
+----+-----+--------+
-- After
select ...
from Invoice01 ;
+----+-----+--------+
| id | TAX | TOTTAX |
+----+-----+--------+
| 11 | 1.0 | 15.0 |
| 22 | 2.0 | 15.0 |
| 33 | 3.0 | 15.0 |
| 44 | 4.0 | 15.0 |
| 55 | 5.0 | 15.0 |
+----+-----+--------+
I would be surprised if this is what you actually want. YMMV.
Regards, Phill W.