i want to sort my table in this manner.
This is the current state of my table:

And this would be the outcome:

So basically in pseudo code it’s:
IF SAME STRING IN "tag" COLUMN THEN add both "power"
Can anyone suggest an efficient way to achieve this if any?
Create a new table called
t1_tempwith the exact same structure as your original table calledt1. The following should get the job done:TRUNCATE t1_temp; INSERT INTO t1_temp (id, power, tag) VALUES (SELECT id, SUM(power), tag FROM t1 GROUP BY tag); RENAME TABLE t1 TO t1_temp2, t1_temp TO t1, t1_temp2 TO t1_tempHowever, I will recommend that you try to modify your insert statement. Create a unique index on
tagand then use something like the following (assuming thatidis auto-increment)INSERT INTO t1 (power, tag) VALUES (3, 'option1') ON DUPLICATE KEY UPDATE power = power + 3