Click here to Skip to main content
15,921,643 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello

i wanted to add a integer value suppose 15 to the mysql database field[integer],
what is the query for that
Posted

Use either an INSERT statement (which will insert a whole row), or an UPDATE statement (which will change just the value)
SQL
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...) (nextvalue1, nextvalue2, ...)

SQL
UPDATE table_name SET field=newvalue, field... WHERE ...
In the second case, be sure to set the WHERE clause, or all rows in the table will be changed!
 
Share this answer
 
Comments
ginnas 22-Sep-12 3:58am    
thanks

but will it add the integer value to the existing value of that filed. i wanted to do like that.means if one field contains a value suppose 20 i wanted to add a 15 to that value,so will your replay achieve this

regards

ginnas
OriginalGriff 22-Sep-12 4:09am    
Ah! You should have said! :laugh:
Try:
UPDATE table_name SET field=field + 15 WHERE ...
Should not be simply this:
SQL
INSERT INTO myTable (someNumericField) VALUES (15)

Refer: My SQL: INSERT Syntax[^]


UPDATE:
SQL
UPDATE myTable SET(someNumericField = someNumericField + 15)
 
Share this answer
 
v2
Comments
ginnas 22-Sep-12 3:58am    
thanks

but will it add the integer value to the existing value of that filed. i wanted to do like that.means if one field contains a value suppose 20 i wanted to add a 15 to that value,so will your replay achieve this

regards

ginnas
Sandeep Mewara 22-Sep-12 4:31am    
:doh: What you want and what you asked!

Updated my answer. Try!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900