Marco M. Marco M. - 2 months ago 7
SQL Question

MySQL Error in the FROM statement

In this error it indicates that the

"FROM is not a valid input at this position".

Here is the code which is an insert statement with JOIN clause

UPDATE phpcollab.projects

SET ph.APPROVED='2',
pd.currentBudget = pd.currentbudget - ph.totalvalue

FROM phpcollab.projects pp JOIN phpcollab.photo ph
ON pp.projectID = ph.id
WHERE ID='1';

Answer

MySQL's update-join syntax doesn't use a from clause:

UPDATE phpcollab.projects pp
JOIN   phpcollab.photo ph ON pp.id = ph.projectID
SET    ph.APPROVED = '2',
       pp.currentBudget = pp.currentbudget - ph.totalvalue
WHERE  ph.id = '1';