473,406 Members | 2,293 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

best way to...

hi all,

I want to decrement all the rows in a column that contain a number that is
bigger then one defined by me.

Is there some function in mysql or php that makes this task easy or do I
have to check row per row and if true decrement the row?

kind regards
Stijn
Jul 17 '05 #1
6 2258
On Fri, 14 Nov 2003 18:57:25 +0100, Stijn Goris wrote:
hi all,

I want to decrement all the rows in a column that contain a number that is
bigger then one defined by me.

Is there some function in mysql or php that makes this task easy or do I
have to check row per row and if true decrement the row?

kind regards
Stijn

$sql = "
UPDATE database.table
SET field = field - 1
WHERE field > '$max'
";
Untested.. but should work =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.

Jul 17 '05 #2
Stijn Goris wrote:
I want to decrement all the rows in a column that contain a number that is
bigger then one defined by me.

Is there some function in mysql or php that makes this task easy or do I
have to check row per row and if true decrement the row?

kind regards
Stijn


Not sure if this is what you're looking for, but by the sounds of it,
you can do this with a simple update query...

UPDATE table_name SET field_name = field_name -1 WHERE field_name >
my_number

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #3
Justin Koivisto wrote:
Stijn Goris wrote:
I want to decrement all the rows in a column that contain a number
that is
bigger then one defined by me.

Is there some function in mysql or php that makes this task easy or do I
have to check row per row and if true decrement the row?

kind regards
Stijn


Not sure if this is what you're looking for, but by the sounds of it,
you can do this with a simple update query...

UPDATE table_name SET field_name = field_name -1 WHERE field_name >
my_number


Once again, I should have checked for newly posted messages before
replying.... ;)

--
Justin Koivisto - sp**@koivi.com
PHP POSTERS: Please use comp.lang.php for PHP related questions,
alt.php* groups are not recommended.

Jul 17 '05 #4

"Ian.H" <ia*@WINDOZEdigiserv.net> wrote in message
news:pa****************************@hybris.digiser v.net...
On Fri, 14 Nov 2003 18:57:25 +0100, Stijn Goris wrote:
hi all,

I want to decrement all the rows in a column that contain a number that is bigger then one defined by me.

Is there some function in mysql or php that makes this task easy or do I
have to check row per row and if true decrement the row?

kind regards
Stijn

$sql = "
UPDATE database.table
SET field = field - 1
WHERE field > '$max'
";
Untested.. but should work =)

Regards,

Ian

--
Ian.H [Design & Development]
digiServ Network - Web solutions
www.digiserv.net | irc.digiserv.net | forum.digiserv.net
Programming, Web design, development & hosting.


thanks,

I didn't know sql could do those operations.

thanks
Jul 17 '05 #5
Justin Koivisto (31.596% quality rating):

UPDATE table_name SET field_name = field_name -1 WHERE field_name >
my_number


Note: if field_name is a unique field or key, you'll need to add an
ORDER BY clause to make sure this works.

/joe
--
In City Cafe, Brian Culver celebrates with the nameserver from Dramatech,
and then emasculates the lethal, aggravating frat house from the Deck(tm).
In 101, Keith links to the website of Kramer for the fiber channel, and
then stimulates a gombizler. Scott Watkins felches Taco ... [tape runs out]
Jul 17 '05 #6
On Fri, 14 Nov 2003 18:45:06 +0000 (UTC), Disco Plumber
<sc**@moralminority.org> wrote:
Justin Koivisto (31.596% quality rating):

UPDATE table_name SET field_name = field_name -1 WHERE field_name >
my_number


Note: if field_name is a unique field or key, you'll need to add an
ORDER BY clause to make sure this works.


But watch out if you're still using MySQL 3.x, as it doesn't support ordered
updates:

mysql> insert into test values (2), (3), (1);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> update test set id = id + 1;
ERROR 1062: Duplicate entry '3' for key 1
mysql> update test set id = id + 1 order by id;
ERROR 1064: You have an error in your SQL syntax near 'order by id' at line 1

--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (http://www.andyh.co.uk)
Space: disk usage analysis tool (http://www.andyhsoftware.co.uk/space)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: John J | last post by:
I've written the following code into a class to search for and display the results of all races entered (The complete code is in a previous thread). I wish to amend the code so as to display the...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
20
by: hagai26 | last post by:
I am looking for the best and efficient way to replace the first word in a str, like this: "aa to become" -> "/aa/ to become" I know I can use spilt and than join them but I can also use regular...
3
by: Irene | last post by:
Hi all, I have set up a simple VB program (and later on an ASP interface) to manage an Athletics database. I'm using Access 2000. To simplify, I have the Athlets, the Competitions and the...
5
by: l.woods | last post by:
I want your recommendation on which ASP.NET Shopping Cart software I should buy? Best code Best documentation Best support (if needed. I will buying source code, if possible) TIA, Larry...
10
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read...
10
by: Ren | last post by:
Hi All, I'm still rather new at vb.net and would like to know the proper way to access private varibables in a class. Do I access the variable directly or do I use the public property? ...
4
by: Ned Balzer | last post by:
Hi all, I am pretty new to asp.net; I've done lots of classic asp, but am just beginning to get my mind wrapped around .net. What I'd like to do is include some code that tests if a user is...
24
by: Earl | last post by:
I have all of my data operations in a separate library, so I'm looking for what might be termed "best practices" on a return type from those classes. For example, let's say I send an update from...
11
by: ankitmathur | last post by:
Hi, I'm trying to overcome a situation whereby I have to search through 4-5 columns and produce the results with an order by according to the values matched in these columns. Example: My...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.