rahulephp Posted October 15, 2010 Share Posted October 15, 2010 I have three columns - id, programname, status I wanted to use UPDATE with IF condition something like this: UPDATE elec_products IF(programname ='Argos') ( SET status = 1 ) ELSEIF(programname ='sify') ( SET status = 2 ) ELSE ( SET status = 3 ) ENDIF WHERE programname IS NOT NULL I am not sure if it'll be possible. Please suggest the best possible ways to do this. Thank you Link to comment https://forums.phpfreaks.com/topic/215924-mysql-how-to-use-update-with-if-else-condition/ Share on other sites More sharing options...
awjudd Posted October 15, 2010 Share Posted October 15, 2010 Try using a CASE statement instead. UPDATE elec_products SET stats = CASE programmename WHEN 'Argos' THEN 1 WHEN 'stify' THEN 2 ELSE 3 END CASE WHERE programmename IS NOT NULL ~judda Link to comment https://forums.phpfreaks.com/topic/215924-mysql-how-to-use-update-with-if-else-condition/#findComment-1122414 Share on other sites More sharing options...
rahulephp Posted October 15, 2010 Author Share Posted October 15, 2010 Thats great. Thanks a lot. Link to comment https://forums.phpfreaks.com/topic/215924-mysql-how-to-use-update-with-if-else-condition/#findComment-1122434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.