Link to home
Start Free TrialLog in
Avatar of Vipin Kumar
Vipin KumarFlag for India

asked on

Add all values of specific columns in a row in MySQL and store in another column of same row

Hi,

I have a table named table_1. In which I have columns col_1, col_2, col_3, col_4 and total. I now insert a row with values for col_1, col_2, col_3 and col_4  as Test, 1, Hello and 2 respectively. I want that the sum of col_2 and col_4 is automatically stored in total column of the same row.

If later the values of col_2 or col_4 or both columns is changed then the value in total column should automatically get updated.

Kindly let me know if anything else is required.

Thanks in advance.
ASKER CERTIFIED SOLUTION
Avatar of arnold
arnold
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would agree with @arnold approach, to calculate that automatically when needed (most probably in a report).
But before jump to that, make sure that you dont need that to show up in many screens of an app, for example. In this case, pre-calculate the value based on triggers would be faster.