Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to compare two table and save result into 3rd table Expand / Collapse
Author
Message
Posted Thursday, August 8, 2013 4:24 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, August 8, 2013 5:17 AM
Points: 3, Visits: 6
table1
number sec
1234 458
6895 458
2543 879
3289 84


table2
number sec
4568 56
3289 46
1236 755
2543 800


i want get result like this
table3
number sec
2543 79
3289 38

table1's and table2's number column are unique , actually i want to do that table1's number column data search in table2 if same data found in table2 then their sec column's data subtract each other

sorry for bad english
Post #1482209
Posted Thursday, August 8, 2013 4:42 AM


SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 10:51 AM
Points: 5,438, Visits: 10,140
Join the two tables on number=number and do t1.sec - t2.sec for the second column of your result set. Make sure you know how you will handle the cases where the subtraction produces a negative number.

John
Post #1482215
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse