Reputation:
Joining two tables to get correct information and update one value from one table by conditioning with some specific conditions
SQL say that it has syntax error at line 5 although it didn't fix the syntax error automatically if he (SQL) knew that
UPDATE
sale
SET
amount = 10000
FROM
sale
JOIN delivery ON delivery.sale_id = sale.id
WHERE
sale.`status` = "active"
AND delivery.services_id = 7;
You have an error in your SQL syntax; it seems the error is around: 'FROM sale JOIN delivery ON delivery.sale_id = sale.id WHERE sale.
status
' at line 5
Upvotes: 0
Views: 48
Reputation: 147216
The correct syntax for a MySQL multi-table update (manual) puts the table references at the beginning of the query:
UPDATE
sale
JOIN delivery ON delivery.sale_id = sale.id
SET
amount = 10000
WHERE
sale.`status` = "active"
AND delivery.services_id = 7;
Upvotes: 1
Reputation: 15105
MySQL doesn't support UPDATE ... FROM (that is a SQL Server feature)
Here is the reference to mySQL update syntax:
https://dev.mysql.com/doc/refman/8.0/en/update.html
Upvotes: 0