Kaloyan Roussev
Kaloyan Roussev

Reputation: 14711

Can I add some value to an int in a database without knowing its current value

lets say I have the following table

players

player_id score
1       - 300
2       - 400

can I do a query that will add 10 to the score of a player?

because right now all I can think of is query the db, get the score, add 10 to it, then query the db and replace 300 with 310?

PS: Im new to SQL

Upvotes: 2

Views: 56

Answers (2)

Rahul Tripathi
Rahul Tripathi

Reputation: 172458

You may try this:-

UPDATE players 
SET score = score + 10 
WHERE player_id = 1

Also check UPDATE in MySQL

Upvotes: 3

John Conde
John Conde

Reputation: 219834

UPDATE players SET score = score + 10 WHERE player_id = 1

Upvotes: 2

Related Questions