ginerjm Posted July 27, 2015 Share Posted July 27, 2015 Having a bit of a problem forming an update query using a CASE statement in it. Can successfully do when using a SELECT query but my syntax is wrong with all the attempts I've made to use UPDATE. Here is my working select query $q = "select machine_seq, CASE machine_seq WHEN $prev_seq then $seq WHEN $seq then $prev_seq END AS new_machine_seq from workout_routines where user_id = '$userid' and routine_id = '$routine' and machine_seq in ($prev_seq,$seq)"; Can someone alter this to an UPDATE query for me? I'm trying to swap two values of the column named 'machine-seq'. Quote Link to comment https://forums.phpfreaks.com/topic/297494-update-query-with-case/ Share on other sites More sharing options...
Ch0cu3r Posted July 27, 2015 Share Posted July 27, 2015 (edited) You assign the column value as the case UPDATE workout_routines SET machine_seq = CASE machine_seq WHEN $prev_seq THEN $seq WHEN $seq THEN $prev_seq END WHERE user_id = '$userid' AND routine_id = '$routine' AND machine_seq IN ($prev_seq,$seq) Edited July 27, 2015 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/297494-update-query-with-case/#findComment-1517479 Share on other sites More sharing options...
ginerjm Posted July 27, 2015 Author Share Posted July 27, 2015 Thx muchly! Quote Link to comment https://forums.phpfreaks.com/topic/297494-update-query-with-case/#findComment-1517489 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.