I have a MySQL database with several tables, two of which look like this:
players
+-----+---------+-------------------+----------------+----------------+--------------+---------------------+ | id | base_id | name | total_searches | auctions_found | auctions_won | created_at | +-----+---------+-------------------+----------------+----------------+--------------+---------------------+ | 283 | 177683 | Christian Eriksen | 12 | 2 | 1 | 2019-05-29 11:25:08 | | 160 | 177683 | Christian Eriksen | 24 | 4 | 1 | 2019-05-29 11:25:08 | | 76 | 345345 | Yan Sommer | 12 | 1 | 3 | 2019-05-29 11:25:08 | | 712 | 4353 | Yannick Carrasco | 42 | 5 | 12 | 2019-05-29 11:25:08 | +-----+---------+-------------------+----------------+----------------+--------------+---------------------+ transactions
+----+-----------+---------------------+ | id | player_id | updated_at | +----+-----------+---------------------+ | 1 | 283 | 2019-05-29 11:25:08 | | 2 | 160 | 2019-05-29 11:25:08 | | 3 | 76 | 2019-05-29 11:25:08 | +----+-----------+---------------------+ As you can see, there are duplicates in the players table (Christian Eriksen). I would like to merge these rows, totalling the total_searches, auctions_found and auctions_won columns. There are several other columns in this table (some omitted here for brevity) which are either the same (eg. base_id) or it's not hugely important which value is retained (eg. created_at).
What is important is the id. Either a new id should be created or, ideally, one of the existing ids retained. The transactions table would then need to be updated with the new player_id.
+-----+---------+-------------------+----------------+----------------+--------------+---------------------+ | id | base_id | name | total_searches | auctions_found | auctions_won | created_at | +-----+---------+-------------------+----------------+----------------+--------------+---------------------+ | 160 | 177683 | Christian Eriksen | 36 | 6 | 2 | 2019-05-29 11:25:08 | | 76 | 345345 | Yan Sommer | 12 | 1 | 3 | 2019-05-29 11:25:08 | | 712 | 4353 | Yannick Carrasco | 42 | 5 | 12 | 2019-05-29 11:25:08 | +-----+---------+-------------------+----------------+----------------+--------------+---------------------+ +----+-----------+---------------------+ | id | player_id | updated_at | +----+-----------+---------------------+ | 1 | 160 | 2019-05-29 11:25:08 | | 2 | 160 | 2019-05-29 11:25:08 | | 3 | 76 | 2019-05-29 11:25:08 | +----+-----------+---------------------+ I don't have any knowledge of SQL so I haven't tried anything yet. Some pointers or ideally a complete solution would be appreciated.