Mysql Question!

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
zolo44
Forum Newbie
Posts: 21
Joined: Tue Jul 30, 2002 11:07 am

Mysql Question!

Post by zolo44 »

Quick Question,

I need to select, add and update a mysql table all in one query. Does anybody have any suggestions?

For example. I need to know the number of a field in a table, once i get the number i need to increament/decreament it by a given number, then i need to update that field.

I need to do it all in one shot cause i have a script that increaments it at least 5 times a second. Now, i know i can do seperate calls but not sure if i would be getting the right amount that percise second.

Not sure if i'm making sence, but can anybody help? I've checked mysql.com and couldn't find anything that could help me.... or i just didn't know what to look for.


thanks
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Something like this should work:

Code: Select all

UPDATE
  some_table
SET
  changing_field = changing_field + 1
WHERE
  id = 'some_id_value'
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
zolo44
Forum Newbie
Posts: 21
Joined: Tue Jul 30, 2002 11:07 am

Post by zolo44 »

Ah man, was that all... I didn't think you could do that.

Thanks for your help... I feel kinda dumb... :)
Post Reply