Jump to content
MakeWebGames

Recommended Posts

Posted

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.

Posted
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)

Posted

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]

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.   Paste as plain text instead

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