0

good afternoon / night, let me tell you, I have a database with several tables and one of them is obsolete since I am trying to pass it to another. I put you in situation. I have the user_accounts table with the following format. "image below"

SQL FORMAT 1

I would like to know if that information can be selected and inserted into another table "users" with this format. "link below"

SQL FORMAT 2

It would be a search for the identifier and the same update for the identifier.

Thanks in advance.

Barmar
  • 741,623
  • 53
  • 500
  • 612
Wolf
  • 13
  • 4

1 Answers1

0

Use JSON_OBJECTAGG()

UPDATE users AS u
JOIN (
    SELECT identifier, JSON_OBJECTAGG(name, money) AS accounts
    FROM user_accounts
    GROUP BY identifier
) AS a ON u.identifier = a.identifier
SET u.accounts = a.accounts
Barmar
  • 741,623
  • 53
  • 500
  • 612