SQL Update Statement

天涯浪子 提交于 2019-12-31 06:54:39

问题


I have 2 tables, Products and ShoppingCart and I would like to update and decrease the product's 'Quantity' of the Products table based on the Product name and Quantity specified in the ShoppingCart. How can i do this?

Table: Products Fields: ProductName, ProductQty

Table: Shopping Cart Fields: ProductName, ProductQty

Access DB


回答1:


You should have a product id. However:

 UPDATE Products p
 INNER JOIN [Shopping Cart] s
 ON p.[Product Name] = s.[Product Name]
 SET p.ProductQty = p.ProductQty - s.ProductQty

You should get rid of spaces in field and table names, as well.



来源:https://stackoverflow.com/questions/9131075/sql-update-statement

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!