MySQL reducing column integer values by 1

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
Hi

This may seem simple but it not working for me.

I currently have the following:

PHP:
UPDATE images SET POPULAR = POPULAR -1 WHERE POPULAR > 0

All I want is to reduce each individual value by one less than the current stored value. Google doesn't seem to give me the answer!

What this statement is doing is taking the first value it finds and using that as the value to update all other fields with the same value... not good.

Do I really have to create a loop for this???????

There must be a simpler mySQL solution...

Rich
 
Last edited:

gomarc

Member
Messages
516
Reaction score
18
Points
18
Hi learning_brain,

There has to be something else affecting the result you expect.

If this is a one time thing, you may want to run your update query from phpMyAdmin and you'll see that it is in fact reducing each individual value of 'POPULAR' by one less than the current stored:

33jmvmg.jpg


Make sure you backup your database, and select the appropriate database/table/SQL tab before running this query. It will work just fine.
 

learning_brain

New Member
Messages
206
Reaction score
1
Points
0
Hmm - you're right.

Something else must be amiss.....

I'll keep digging.

---------- Post added at 07:08 PM ---------- Previous post was at 06:21 PM ----------

Sorry - just worked it out.

I didn't include the whole statement for ease of understanding but there was another variable control which had a conflict with NULL values.

Job sorted.

Rich
 
Top