Link Details

Link 76663 thumbnail
User 208552 avatar

By indy2kro
via blog.bubble.ro
Published: Apr 21 2008 / 07:20

Here's an interesting trick you can use to run multiple UPDATEs in a table using a single query.
  • 9
  • 8
  • 1923
  • 744

Comments

Add your comment
User 1 avatar

rick replied ago:

1 votes Vote down Vote up Reply

Interesting technique, Indy.

User 246188 avatar

kbilsted replied ago:

0 votes Vote down Vote up Reply

this hack will destroy any db with a reasonable size. don't do it!
,

User 212108 avatar

legendx replied ago:

0 votes Vote down Vote up Reply

That is a horrific idea. Title should be: "Update 2 records by updating everything else with itself". Kudos for thinking outside the box but what made you think this would save time?

User 208552 avatar

indy2kro replied ago:

0 votes Vote down Vote up Reply

The whole idea was to make a single update query instead of 1000. In the end it seems it's better to run 1000 update queries indeed as long as you do them all at once (eventually in a transaction).

User 246188 avatar

kbilsted replied ago:

-1 votes Vote down Vote up Reply

Try batching the queries in your driver.. that will essentially reduce the number of requests to the DB to a minimum! Move away from lame PHP and try doing stuff in a real programming language.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.