Query sql to subtract two table values ​​and save them in the first table?

advertisements

How do I subtract one table column value from another table column value, and save the value in the first table column in the process?

Thanks for your help.


Where tablename is the table and col1 is the first column and col2 is the second column.

UPDATE tablename SET col1 = (col2 - col1)

If you are meaning that the values are coming from different tables then the query is much the same:

UPDATE tablename SET col1 = ((SELECT col2 from tablename2) - col1)