-1

I am going to execute SQL command on my multiplayer game, I don't wanna any game stop or something like that because I am going to lose players so everything must go smooth.

Its my command :

UPDATE `players`
   SET `mana` = `mana` + 500 WHERE `vocation` != "121;122;123;124;125;126" 
   AND `id` IN (SELECT `player_id` FROM `player_storage` WHERE `key` = 25128 AND `value` = 15 GROUP BY `player_id`);

I want to update every vocation that is not 121 OR 122 OR 123 OR 124 OR 125 OR 126

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54

3 Answers3

1

You can use NOT IN to filter values that are not in a list.

WHERE vocation NOT IN (121, 122, 123, 124, 125, 126)
D Stanley
  • 149,601
  • 11
  • 178
  • 240
0

Use BETWEEN

     ....Where location
    not between 120 
    and 
    127
Himanshu
  • 3,830
  • 2
  • 10
  • 29
  • 1
    While this will work for this particular situation, `NOT IN` would be closer to the original intent. – D Stanley Dec 11 '19 at 20:45
  • But adding manual values and that too at such frequencies would be a bad practice. This works for all consecutive data just that replace the between values – Himanshu Dec 11 '19 at 22:51
  • suppose vocation # 130 needs to be added to the list, or #125 removed - what do you do? I'm not saying it's a _terrible_ solution, but there no obvious relationship between these IDs to indicate that a `between` is a natural way to think of them - they just _happen_ to be consecutive. – D Stanley Dec 12 '19 at 13:32
0

If you have the list as a string of values with delimiter ; you can use FIND_IN_SET():

WHERE FIND_IN_SET(`vocation`, REPLACE('121;122;123;124;125;126', ';', ',')) = 0
forpas
  • 160,666
  • 10
  • 38
  • 76