简体   繁体   English

通过联接3个表来更新表

[英]Update a table by joining 3 tables

i have 3 tables: 我有3张桌子:

  • tblproduct (pro_Id, qty, unitprice) tblproduct(pro_Id,数量,单价)
  • tblorderdetails (order_id, pro_Id, qty) tblorderdetails(order_id,pro_Id,数量)
  • tblorder (order_id, totalAmount) tblorder(order_id,totalAmount)

i intend joining these tables to as to update the totalAmount in the tblorder table . 我打算加入这些表为以更新tblorder表总价 This is my query using MySql console: 这是我使用MySql控制台的查询:

UPDATE o
SET o.totalAmount = p.unitprice * d.qty
FROM tblorder o INNER JOIN tblorderdetails d
on o.order_id = d.order_id
INNER JOIN tblproduct p
on p.pro_Id = d.pro_Id;

This is the error i get: 这是我得到的错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to use
near 'from tblorder o inner join tblorderdetails d

The syntax is not correct and it should be as 语法不正确,应为

UPDATE  tblorder o
INNER JOIN tblorderdetails d
on o.order_id = d.order_id
INNER JOIN tblproduct p
on p.pro_Id = d.pro_Id
SET o.totalAmount = p.unitprice * d.qty ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM