SQL将2个表合并为一个表,更新缺失值

时间:2015-01-17 21:01:05

标签: mysql sql

我有3张桌子:

users, user_profile, plus

我想将表用户 user_profile 合并,并将缺失值填入表。参考文献标有颜色的图像。

plus表中的唯一键是email列。

表和参考文献:

tables

1 个答案:

答案 0 :(得分:0)

UPDATE plus AS p
JOIN users AS u ON p.email = u.email
JOIN user_profile AS up ON up.user_id = u.id
SET p.reg_date = u.reg_date, p.nickname = up.nickname, p.name = up.name,
    p.surname = up.surname, p.birthday = up.birthday, p.gender = up.gender