简体   繁体   中英

MySQL Merge Two Tables together

I'm not the best in MySQL but currently on a tidy up task, not sure if this is possible or ill have to make a script to do this using inserts.

But i have two tables AccountInfo and AccountLogin they both share the same PK so id1 will match id1 in the other table. What im trying to do is get both tables merged into one table either called Account or merge into a table of the two and rename after.

Any help or advice will be appreciated.

Create table "Members" with columns: id, other columns of AccountInfo, other columns of AccountLogin.

Then, like Lelio Faieta said, INSERT INTO Members SELECT id, other columns of AccountInfo ai, other columns of AccountLogin al FROM AccountInfo ai INNER JOIN AccountLogin al ON (al.id = ai.id).

Also, if there are AccountInfo rows without matching AccountLogin rows you can use a LEFT JOIN instead of an INNER JOIN.

Disclosure: I usually use Oracle, so I might make a mistake with MySQL.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM