我想根据同一个表中存在的id来更新一行。换句话说,id是其他表中的主键,只是我要更新的表中的一列。
我想基于相同的ID进行更新。
我有这个查询但由于SQL语法而无法正常工作。
UPDATE
transaction
SET
DaysRented = 3,
Cost = 3,
TotalCost= 5
FROM
transaction
INNER JOIN
rentals
ON
transaction.idRentals = rentals.idRentals;
答案 0 :(得分:2)
您正在使用SQL Server update
/ join
语法。正确的MySQL语法是:
UPDATE transaction INNER JOIN
rentals
ON transaction.idRentals = rentals.idRentals
SET DaysRented = 3,
Cost = 3,
TotalCost = 5;
答案 1 :(得分:2)
mysql的语法
http://www.mysqltutorial.org/mysql-update-join/
UPDATE transaction
INNER JOIN rentals ON transaction.idRentals = rentals.idRentals
SET DaysRented = 3,
Cost = 3,
TotalCost = 5;