[SOLVED] Editing all values in a row by a curtain number

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
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

[SOLVED] Editing all values in a row by a curtain number

Post by mickd »

Hi, i was just wondering if there was a way to edit all values in a row in a mysql database. any help appriciated. sorry if this question is simple, i must just not be noticing something.

heres an example.

Database

Table example1
ID, Name, Lastname, Number
1, John, Smith, 3
2, David, Spring, 1
etc

im wondering if theres a way to increase all numbers in the number column by 3 for example so itll be

Table example1
ID, Name, Lastname, Number
1, John, Smith, 6
2, David, Spring, 4
etc

thanks for any help.
Last edited by mickd on Thu Jul 21, 2005 1:03 am, edited 1 time in total.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

Sure there is, if you want to update an existing field in a dbase just use:

update <tablename> set <fieldname>=<fieldname>+3 <where clause if you want to use it>

As long as your base field has int, bigint, or tinyint it should work fine.. :)

Btw there are no simple questions, right? We all started from scratch.. :)
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Post by mickd »

cool thanks for the reply, ill check it tomorrow after school hope it work :) 1 am now for me, gotta go sleep :(

EDIT: ok checked worked :)
Post Reply