MySQL Join offer in update

When trying to execute this query:

>mysql_query("UPDATE contracts SET x = '1' FROM contracts INNER JOIN employees ON contracts.contract_employeeid=employees.employee_id WHERE experience >= '6'") or die(mysql_error()); 

The following error message appears:

You have an error in the SQL syntax; check the manual that matches your version of MySQL server for the correct syntax for using a number of contracts FROM INNER JOIN employees ON contracts.contract_employeeid = employees.employee_id WHERE experience> = '6'

In words, I need to set x = 1 on the “contracts” table for employees with more than 6 years of experience (for this I need to join the “employees” table on employee_id = contract_employeeid, since their experience is stored in this table)

+4
source share
2 answers

You can probably move the JOIN part of your query before the SET statements:

 UPDATE contracts INNER JOIN employees ON contracts.contract_employeeid = employees.employee_id SET x = '1' WHERE experience >= '6' 
+4
source
 UPDATE contracts, employees SET contracts.x = '1' WHERE contracts.contract_employeeid=employees.employee_id AND employees.experience >= '6' 
+1
source

All Articles