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.
Author |
Topic |
javad.nikoo
Starting Member
17 Posts |
Posted - 2011-07-23 : 02:15:21
|
HII have 2 table withe the same fild for ex T1:Id Countt1:IdCountsome time the data are the sameNOW ,What I Want,Let me explaini need another table with this strucurethis table(t3) is like thisID >>>comes from t1 or T2 (Id Filed(Join))Count >> T1.count-t2.count(if T1.id was in t2(t2.id) else t1.conut or t2.count ) (I did IT but It cost tooo much for me )Please What is The Best way Too join This Tables[]==[] |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-23 : 04:17:29
|
[code]insert into T3select id, sum([count]) from(select id,[count]from t1union allselect id,[count]from t2)tgroup by id[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
javad.nikoo
Starting Member
17 Posts |
Posted - 2011-07-24 : 00:12:31
|
thanks for your Replybut as i explained id do not want the sum of this tables count filed(t1.count and t2.count) what i want is this i want this t1.count-t2.count if the code were same in both of this table and if it does not put t1.count or t1.count in t3.count and union is so expensive my tables have too much dataBest Regard'sJAVAD NIKOO |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-24 : 00:55:45
|
[code]select coalesce(t1.id,t2.id),ABS(t1.count-t2.count)from t1full join t2in t1.id = t2.id [/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
javad.nikoo
Starting Member
17 Posts |
Posted - 2011-07-25 : 00:17:04
|
hi thanks visakh16i test it and it work correctly for mebest Regard's javad.nikoo |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2011-07-25 : 00:28:33
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|