簡體   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