November 8th, 2015, 01:27 AM
Question about MySQL
Hello there, I've a gaming community.
And am trying to make something through the MySQL database, I want to set their money to a specific number, depends on the current money.
For example if someone has $10 milion, I want to set it to $1 million, is there any code to search for users with 10million and replace it to 1milion?
It was just an example, i need a code like this to search for a specific number and replace it to another number.
November 8th, 2015, 02:37 AM
Make sure you actually want "replace 10M with 1M" and not, say, "replace >1M with 1M".
UPDATE table SET field = new number WHERE field = old number
November 8th, 2015, 10:33 AM
Alright, i will check it when am back home.
(Pcash (Table name) = for player's cash)
UPDATE Pcash SET field = 1.000.000 WHERE field = 10.000.000
Is it right?
November 8th, 2015, 11:11 AM
No, remove the dots from the numeric literals. Whole numbers in SQL are written without punctuation.
November 8th, 2015, 11:21 AM
Oh, alright will try it when am back home thanks.
November 9th, 2015, 11:56 AM
It's worth running a quick SELECT with the same WHERE clause, before you run the update so you can see the records that will be affected by the UPDATE.
SELECT * FROM Pcash WHERE field = 1000000
Comments on this post