chaoswar4u Posted February 8, 2010 Posted February 8, 2010 Can the following 2 queries be merges as one - $db->query("UPDATE users SET energy=maxenergy WHERE userid=$userid AND test1 > 0 "); $db->query("UPDATE users SET will=maxwill WHERE userid=$userid AND test2 > 0 "); As you can see they both have different where claues. Is there a mehod to merge the query but still obtain the same goal? Any help as always has many thanks in advance. Quote
a_bertrand Posted February 8, 2010 Posted February 8, 2010 Not as far as I'm aware of... due to the 2 different where conditions. Quote
Dayo Posted February 8, 2010 Posted February 8, 2010 --- post removed --- re looking over it you have to use the two querys Quote
Lithium Posted February 8, 2010 Posted February 8, 2010 Can the following 2 queries be merges as one - $db->query("UPDATE users SET energy=maxenergy WHERE userid=$userid AND test1 > 0 "); $db->query("UPDATE users SET will=maxwill WHERE userid=$userid AND test2 > 0 "); As you can see they both have different where claues. Is there a mehod to merge the query but still obtain the same goal? Any help as always has many thanks in advance. Despite what a_bertrand says... there are definetly 2 where conditions though a common field within the where clause. So, something along these lines might just do the trick. The code is not tested, only a guideline to the solution ;) UPDATE users SET energy = IF(test1 > 0, maxenergy), will = IF(test2 > 0, maxwill) WHERE userid=$userid And i assume the common denominator on both queries is the $userid (equal for both queries) Quote
fbiss Posted February 8, 2010 Posted February 8, 2010 Lithium, Wouldn't you need a condition on your statement if its false? [mysql] UPDATE users SET energy = IF(test1 > 0, maxenergy, energy), will = IF(test2 > 0, maxwill, will) WHERE userid=$userid [/mysql] Quote
Lithium Posted February 8, 2010 Posted February 8, 2010 Quite right! But you could let it be for people to think it over :P i pointed out on the right direction, so it would be easier for them to reach it on their own :) Quote
a_bertrand Posted February 8, 2010 Posted February 8, 2010 Yes the IF should work. Not sure if it makes sense however performance wise and certainly doesn't for readability. However good thinking ;) Quote
Zero-Affect Posted February 8, 2010 Posted February 8, 2010 There are alot of MySQL functions people don't use much on here, LEAST for example. Quote
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.