I would like to pass data from a table with several columns to another table in a single column

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”

I would like to pass data from a table with several columns to another table in a single column

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

I would like to pass data from a table with several columns to another table in a single column

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

Thanks in advance.

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x