Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL subtraction

Status
Not open for further replies.

NeilV

Programmer
Oct 14, 2002
117
GB
Hello...

I have a table which has a field that holds an integer value. What I want to do is calculate the difference(ie
subtract) of this field for my selected records. eg

Code:
ID       Value
----------------
1         30
2         10

Get the difference of value between record 1 and record 2 (30-10=20)
I thought this would be pretty simple, but I cant figure it out!

Help!
Neil
 



select t2.value - t1.value
from mytable t1, mytable t2
where t1.id = 1 and t2.id = 2
 
Thanks mija! That did the trick! :-D
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top