close

Update data in one table with data from another table.
假設 History table 只有 Product_id, 現在新增 Product_Name column, 但資料再另一個 table 有, 要怎樣更新.


以往使用 MS SQL 做這件事非常簡單, 語法也很易懂.

update history 
set product_name=product.product_name
from history, product
where history.product_id=product.product_id


如果是 Oracle : 

update history h
set product_name=(select product_name from product p where p.product_id=h.product_id)
WHERE EXISTS( SELECT product_name FROM product p where p.product_id=h.product_id)

arrow
arrow
    全站熱搜

    py3939 發表在 痞客邦 留言(0) 人氣()