S.M Talha S.M Talha - 3 months ago 7
MySQL Question

I am trying to use join with update query but cant find the issue

Please help me to correct the syntax

UPDATE
user_shift_test
SET
shifttime='01:00-21:00'
FROM
user_shift_test
INNER JOIN swaps
ON
user_shift_test.userid=swaps.csrid
WHERE
user_shift_test.userid=5


This error am getting


1064 - 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 user_shift_test INNER JOIN swaps ON user_shift_test.useri'
at line 5

Answer

Try this:

UPDATE user_shift_test
INNER JOIN swaps 
ON user_shift_test.userid=swaps.csrid and user_shift_test.userid=5
SET shifttime='01:00-21:00'

(I am assuming that you are trying to do an update query using a JOIN)