最初我必须从旧表中获取ip并将其放入新表中,电子邮件在这两个表中都匹配。
INSERT INTO new (ip)
SELECT old.ip
FROM old
INNER JOIN new on old.email = new.email;
我现在需要更改此查询以执行以下操作:
从旧表中获取ip
将它与新表格中该行的电子邮件相匹配
从新表中获取user_id
使用user_id和ip
到目前为止的查询:
这是否接近?似乎不对:/
comb_uid = SELECT old.ip FROM old
WHERE new.email = old.email
comb_ip = SELECT new.user_id FROM new
INSERT INTO combined (user_id, ip)
VALUES comb_uid, comb_ip
答案 0 :(得分:0)
new
更改为combined
。
INSERT INTO combined (ip, user_ID)
SELECT old.ip, new.user_ID
FROM old
INNER JOIN new
on old.email = new.email;
更新1
INSERT INTO combined (ip, user_ID, status)
SELECT old.ip, new.user_ID, 'approved'
FROM old
INNER JOIN new
on old.email = new.email;