English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I want to increment or decrement the value of a field in a mysql table and i was wondering if there is an easier way than what i thought of...
1. Get value, 2. value++, 3. Update value on Mysql.
That seems really inefficient to me (2 query calls just to push a number up by one), so i thought maybe mysql has a function to do this automatically. Thanks for the help.

2006-08-09 06:41:43 · 3 answers · asked by Brady 3 in Computers & Internet Programming & Design

3 answers

You can do it with a single UPDATE query:

UPDATE the_table SET the_field = the_field + 1
WHERE [your WHERE clause]

2006-08-09 06:46:36 · answer #1 · answered by NC 7 · 0 1

you can use a query to increment or decrement a field in just one query:

"update table set field = field+1 where ..."

2006-08-09 06:47:58 · answer #2 · answered by John J 6 · 0 0

The good judgment seems real. yet i think of you go with expenses around the replace assertion, by way of fact it relatively is a string. attempt doing it in smaller steps, and print out the sq. replace statements by way of fact this technique runs, this way it's going to be much less complicated to debug: for($i=0; $i

2016-12-11 05:48:32 · answer #3 · answered by ? 4 · 0 0

fedest.com, questions and answers