Jump to content

Is it possible to do 4 updates in 1


Bitweiser

Recommended Posts

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...???

 

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.