我試過了幾種方法來從另一個表更新mySQL數據庫表中的列,但沒有任何運氣。從另一個表更新列 - mySQL 3.5.2
我在某處讀到版本3.5.2不支持多表更新,我需要一個基於代碼的解決方案 - 是正確的嗎?
如果沒有人能指出我在正確的方向使用SQL?
UPDATE products SET products_ordered = (
SELECT SUM(products_quantity)
FROM orders_products
WHERE products_id = products.products_id
);
或:
Create temporary table my_temp_table
as
SELECT products_id, SUM(products_quantity) as total
FROM orders_products
GROUP BY products_id
UPDATE products, my_temp_table
SET products.products_ordered = my_temp_table.total
WHERE products.products_id = my_temp_table.products_id
順便說一句,你確定你的版本正確嗎? – Node 2008-10-14 09:08:38