From: "Ben Miller" on
I hope this isn't a bone-head question - Is there a MySQL query that will
increment/decrement the value in an integer column with a single query - in
other words, I don't have to run a SELECT query to get the value,
add/subtract to/from the value, and then run an UPDATE query to store the
new value?



Thanks in advance.



Ben

From: Robert Cummings on
Ben Miller wrote:
> I hope this isn't a bone-head question - Is there a MySQL query that will
> increment/decrement the value in an integer column with a single query - in
> other words, I don't have to run a SELECT query to get the value,
> add/subtract to/from the value, and then run an UPDATE query to store the
> new value?

You mean:

UPDATE table SET column = column + 1;

?

Cheers,
Rob.
--
http://www.interjinn.com
Application and Templating Framework for PHP
From: "Bipper Goes!" on
UPDATE SQLTABLE SET count = (count+1) WHERE PromoID=1

Is this valid for your issue? I have no way of testing or toying

On Mon, Dec 28, 2009 at 8:54 PM, Ben Miller <ben(a)tottd.com> wrote:

> I hope this isn't a bone-head question - Is there a MySQL query that will
> increment/decrement the value in an integer column with a single query - in
> other words, I don't have to run a SELECT query to get the value,
> add/subtract to/from the value, and then run an UPDATE query to store the
> new value?
>
>
>
> Thanks in advance.
>
>
>
> Ben
>
>
From: Eric Lee on
Ben

It seems that you can just update the column with a update query like this,

update table set field = field + 1 where some condition

This might be the thing you need.


Eric



On 12/29/09, Ben Miller <ben(a)tottd.com> wrote:
>
> I hope this isn't a bone-head question - Is there a MySQL query that will
> increment/decrement the value in an integer column with a single query - in
> other words, I don't have to run a SELECT query to get the value,
> add/subtract to/from the value, and then run an UPDATE query to store the
> new value?
>
>
>
> Thanks in advance.
>
>
>
> Ben
>
>
From: muzy on
Hello Ben,

I had the same question yesterday (but with SQLite) and there are at
least 2 solutions.

The first was already mentioned:

UPDATE table SET value = value + 1 WHERE foo = bar;

The second solution which also works is:

UPDATE table SET value = (SELECT value FROM table WHERE foo = bar) + 1
WHERE foo = bar;


I hope it helps.


Greetings from Germany,


Sebastian

Ben Miller wrote:
> I hope this isn't a bone-head question - Is there a MySQL query that will
> increment/decrement the value in an integer column with a single query - in
> other words, I don't have to run a SELECT query to get the value,
> add/subtract to/from the value, and then run an UPDATE query to store the
> new value?
>
>
>
> Thanks in advance.
>
>
>
> Ben
>
>
>

 |  Next  |  Last
Pages: 1 2
Prev: SQL Queries
Next: Merry Xmas and Happy New year