I'm building a point of sale software in php
So I've saved the items in the cart in a temporary table called tempsales, then update all the quantity of items with the new quantities. Just one query, using the code below which gives me subquery, returns:
More than one row error
UPDATE items SET quantity = quantity -
(SELECT quantity FROM tempsales ORDER BY id ASC)
WHERE id IN
(SELECT id FROM ORDER BY I'd ASC)
It looks like you want to update a whole mess of rows in your items
table based on the rows in your tempsales
table. I think you want to match the id
values. That requires using JOIN
syntax in your UPDATE
query, like this.
UPDATE items
JOIN tempsales ON items.id = tempsales.id
SET items.quantity = items.quantity - tempsales.quantity
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.