dtsnx44260 2012-05-29 10:09
浏览 31

如何使用另一个表中的数据更新表

im using php as my language, and oracle xe for my database.

i have table Order_details that store item_id, quantity.The table currently only hold data for item_id, while the quantity has null value.Lets say the item id is 038

i created another table order_details2 as a temp table that have the same row which is item_id,quantity. This table contains data for both item_id, and quantity which is 038, and 3

the problem is, i dont know how to use data in order_details2.quantity which is 3 to insert it into order_details.quantity using the same references item_id

can any1 please show me, how am i doing this? im very new to programming..

  • 写回答

1条回答 默认 最新

  • dqpd4268 2012-05-29 10:24
    关注

    If I understand correctly what you're after, then something like this should work:

    UPDATE
        (SELECT o1.item_id as id1, o1.quantity as qty1, o2.item_id as id2, o2.quantity as qty2
           FROM order_details o1
           JOIN order_details2 o2 on o1.item_id = o2.item_id) t
    SET t.qty1 = t.qty2
    

    You have to be careful about duplicate item_id values in any of the tables though.

    评论

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探