Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Subtract rows from 2 tables

Author  Topic 

hobartit
Starting Member

2 Posts

Posted - 2010-12-13 : 12:14:35
I am a new comer to SQL and i am looking for the correct syntax to be able to subtract rows from 2 different tables. I have 2 tables both which include 2 columns. 1 called ticker and the other amount. I need to be able to subtract the amounts where the ticker in table 1= ticker in table 2.

Table 1
ticker, amount
ADN.L, 26000.00
AFE.L, 750000.00
EDIN.L, 25000.00
EGU.L, 3553.00

Table 2
ticker, amount
ADN.L, 46000.00
AFE.L,850000.00
EDIN.L,35000.00
EGU.L,4553.00


I hope this makes sense, if you need further clarification please let me know. Any help much appreciated.

russell
Pyro-ma-ni-yak

5072 Posts

Posted - 2010-12-13 : 13:05:55
[code]SELECT t2.ticker, t2.amount - t1.amount as diff
FROM Table1 t1
JOIN Table2 t2
On t1.ticker = t2.ticker[/code]
Go to Top of Page

hobartit
Starting Member

2 Posts

Posted - 2010-12-14 : 03:34:22
Russell


A maassive thanks for your help with this. Really appreciate it.

If anyone has any recommendations on any good websites for learning SQL. Would really like to get to grips with it

Regards
Go to Top of Page
   

- Advertisement -