![](/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.