Reuse of a Sum() Result

I have a table with a column named TAX. I find I am unable to do anything with the Sum of the TAX and use it as a value. I am using MySQL.

In the example below, I am trying to copy the Sum of the TAX into a field called TOTTAX.

SELECT SUM(TOTAL) AS "TTotal" FROM Invoices01;
Update Invoices01 set TOTTAX = TTotal;

This code does not work.

Any suggestions would be appreciated.

Mike

Hi @mdsmith1 Can you try putting the select statement inside the update statement like this:

Update Invoices01 set TOTTAX = (SELECT SUM(TOTAL) AS TTotal FROM Invoices01)

Tess:

I got the code below from Henry and it works fine. He replied through the Forum, I think, in this same Topic.

SELECT @TTax:=SUM(TAX) FROM Invoices01;
update Invoices01 set TOTTAX = @TTax;

So I am out of the woods.

Thank you for your reply.

Mike

Ah okay great! :blush: :raised_hands: