[英]How to combine these 3 things: “check if ID is legitimate from other table”, then “Insert” or “Update” by using Just 1 query
[英]How to update SQL query with ID reference from other table?
我有表A:
id name product_id shipped
1 Apple 10 100
2 Orange 11 110
3 Banana 12 0
4 Mango 13 0
和表B:
id product_id qty order_id
1 10 100 2
2 11 110 2
3 12 120 3
4 13 130 2
我需要更新數量
UPDATE table_B SET qty=0 WHERE order_id=2
AND table_B.product_id = table_A.product_id
table_A.product_id是從腳本獲取的。 我怎樣才能做到這一點? 謝謝
UPDATE table_B b
LEFT JOIN table_A a
ON b.product_id = a.product_id
SET b.qty= 0 WHERE b.order_id=2
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.