我想將值插入一個表中,值來自不同的表以及一個 php 檔案,但我還需要一個 where 子句。我不知道如何做到這一點,所以任何幫助都會得到解決。
了解發生了什么的當前 SQL 是:
INSERT INTO order1(Order_ID,Supplier_ID,Product_ID,Stock_Amount,Reorder_Time,Postcode Amount_Ordered,Telephone_Number) VALUES(product.product_ID,:supplier_ID,product.Stock_Amount,:stockamount,supplier.Reorder_Time,supplier.Postcode,:Amount_Ordered,supplier.Telephone_Number) WHERE product.product_ID=:product_ID
(:變數只是 php 檔案傳入的一些資料,產品和供應商只是其他表)
代碼不需要高效它只需要作業,非常感謝任何幫助
uj5u.com熱心網友回復:
您可以將其表述為INSERT INTO ... SELECT:
INSERT INTO order1 (Order_ID, Supplier_ID, Product_ID, Stock_Amount,
Reorder_Time, Postcode, Amount_Ordered, Telephone_Number)
SELECT product_ID, :supplier_ID, Stock_Amount, :stockamount, Reorder_Time, Postcode,
:Amount_Ordered, Telephone_Number
FROM order1
WHERE product_ID = :product_ID;
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/439655.html
