![](/img/trans.png)
[英]MYSQL: I have two tables. I want to show data from table 1 and table 2 using FK in table 1
[英]I have two tables both A and B. I want to insert data from table B to A using an inner join
我有两个表country
和country_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.