944,112 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Marked Solved
  • Views: 842
  • MySQL RSS
Sep 27th, 2009
0

Substract two field values to insert the result into a third value

Expand Post »
Hi,

I have this question, having two numeric values field1 and field2, i need field3 by default to be the difference between field1 and field , any idea??
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
josjorge is offline Offline
1 posts
since Sep 2009
Sep 28th, 2009
0

Re: Substract two field values to insert the result into a third value

in one query:
MySQL Syntax (Toggle Plain Text)
  1. UPDATE table SET field3 = field1-field2

I think this should work.

(everytime you update/change a value of field1/field2 you will have to do this query, mysql can't do this automatic..)
Last edited by Kruptein; Sep 28th, 2009 at 7:10 am.
Reputation Points: 25
Solved Threads: 11
Posting Whiz in Training
Kruptein is offline Offline
258 posts
since Sep 2009
Oct 5th, 2009
-1

Re: Substract two field values to insert the result into a third value

or you can like be all cool and be like well find the column names and then do it with php $column1 - $ column2
Reputation Points: 15
Solved Threads: 7
Posting Pro in Training
SKANK!!!!! is offline Offline
428 posts
since Apr 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: help with mysql SELECT statement
Next Thread in MySQL Forum Timeline: Columns addition





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC