I wrote a sql query to update data of ‘tbl_products’. Here is the query
update tbl_products set product_count = (product_count - tbl_order_details.product_sales_quantity) from tbl_products join tbl_order_details on tbl_order_details.product_id = tbl_products.product_id join tbl_order on tbl_order.order_id = tbl_order_details.order_id where tbl_order.order_id = 54;
But it gives me the following error “#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ‘from tbl_products join tbl_order_details on tbl_order_details.product_id = tbl_p’ at line 1”
Whats wrong here?
Advertisement
Answer
In MySQL, the correct syntax is:
update tbl_products p join tbl_order_details od on od.product_id = p.product_id join tbl_order o on o.order_id = od.order_id set p.product_count = (p.product_count - od.product_sales_quantity) where o.order_id = 54;