Bitweiser Posted September 14, 2010 Share Posted September 14, 2010 I have a table with telecom information about persons like this: +------+-----+-------------+ | user | id | value | +------+-----+-------------+ | 5001 | TEL | 555-54-1234 | | 5001 | FAX | 555-54-5678 | | 5001 | EMA | me@you.com | +------+-----+-------------+ Now I have a page with these 3 input fields. On submit I do my update query1="Update tabel value1='ABC' where user=5001 and id=TEL" query2="Update tabel value2='DEF' where user=5001 and id=FAX" query3="Update tabel value3='GHI' where user=5001 and id=EMA" This works fine, but I use 3 update statements. If you know I have this information 4 times in my page then there are 12 updates only for the telecom information. Million dollar question: Is there a way to do this in 1 query...??? Quote Link to comment https://forums.phpfreaks.com/topic/213374-is-it-possible-to-do-4-updates-in-1/ Share on other sites More sharing options...
kickstart Posted September 14, 2010 Share Posted September 14, 2010 Hi Should be possible with something like this:- UPDATE tabel SET value = CASE WHEN user=5001 and id='TEL' THEN 'ABC'; WHEN user=5001 and id='FAX' THEN 'DEF'; WHEN user=5001 and id='EMA' THEN 'GHI'; ELSE value END; I suspect it isn't that efficient as it will update every single row on the table (just any that are not specified are updated to their current value). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/213374-is-it-possible-to-do-4-updates-in-1/#findComment-1110922 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.