Sameer M
Sameer M

Reputation: 3

How do I add an amount to an existing value in sql?

Lets say I have a table with multiple records.

Table1

ID    Name    Balance  
1     Ken     25.58  
2     Bob     18.52  
3     Billy   24.58  
4     Al      14.85

How would I add an amount, say 34.50 to the balance for Billy using SQL?

I'm kinda new to this so please help me.

Upvotes: 0

Views: 348

Answers (1)

Anson Fong
Anson Fong

Reputation: 560

The Sql statement will be:

UPDATE Table1
SET Balance = Balance + 34.50
WHERE ID = 3;

More Details as suggested by @Clay. I explain more in detail why I use ID in the where clause in below:

Changing records in "Name" field is very normal in real world. Let say Billy would like to change his name in your system to "Billie", using ID in the where clause will not be affected by the name change.

Upvotes: 3

Related Questions