![](/img/trans.png)
[英]How to put values from one table to another WHERE column1 of table1 = column2 of table2?
[英]How to insert into a table1 column where another table1 column is the same as table2 column
我正在嘗試將產品類型插入到我的名為ro_frames
表中,該表可以從表ro_st_product
訪問,其中ro_frames.product_id = ro_st_product.product_id
。
為此,我使用以下查詢:
insert into ro_frames(product_type)
(SELECT a.producttype
FROM ro_st_product a join ro_frames b on a.product_id = b.product_id
where a.product_id = b.PRODUCT_ID);
它說:
操作:插入 1,405 行。
但是,當我轉到ro_frames
, product_type
列中的值全部為空。 為什么會發生這種情況,我該如何解決?
您正在插入新行。 我想你想要update
:
update ro_frames f
set product_type = (select a.producttype
from ro_st_product p
where p.product_id = f.PRODUCT_ID
);
也就是說,您不應該在兩個地方存儲相同的值。 當您查詢從產品表中獲取類型時,您應該只使用join
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.