繁体   English   中英

我有两个表A和B。我想使用内部联接将数据从表B插入到A

[英]I have two tables both A and B. I want to insert data from table B to A using an inner join

我有两个表countrycountry_list 两者都有相似的列和内容,我想转移country_list表中的所有国家代码( country_code列),并将数据插入到国家表中也有country_code列但为空的所有匹配国家中。 我有一个关于从内部加入country_name列开始的想法,因为它们具有相似的值,但是哪种方法最好呢?

您可以尝试更新联接:

UPDATE country c
INNER JOIN country_list cl
    ON c.country_name = cl.country_name
SET
    c.country_code = cl.country_code;

您可以将INSERT语句与INNER JOIN一起使用

INSERT INTO country (country_code)
SELECT country_code from country_list countryList
INNER JOIN country c ON c.country_name = countryList.country_name;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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