S.M Talha
S.M Talha

Reputation: 59

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

Upvotes: 1

Views: 52

Answers (3)

Rosh
Rosh

Reputation: 41

UPDATE user_shift_test
SET shifttime='01:00-21:00'
WHERE userid IN 
               (SELECT user_shift_test.userid
                FROM user_shift_test
                JOIN swaps ON swaps.csrid=user_shift_test.userid
                WHERE 
                user_shift_test.userid=5
               );

Upvotes: 2

Delano zuurman
Delano zuurman

Reputation: 234

this should do it

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

Upvotes: -2

Rahul Tripathi
Rahul Tripathi

Reputation: 172578

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)

Upvotes: 1

Related Questions