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 |
|
cheesecake
Starting Member
11 Posts |
Posted - 2010-08-13 : 13:26:57
|
| Hi,I have a table "Test" with 2 columns VehicleId and StandardDeviation and the data looks likeVehicleId Std.Dev.500 2500 2600 3600 3I have a copy of this table which has fewer rows but similar data i.e. duplicate values. I am wondering how can I find the difference between these two tables. I want to publish the difference between these two in a diff table i.e.Rows in table 1 but not in table 2Rows in table 2 but not in table 1Rows in both the tables but have different dataThanks,CZCaKe |
|
|
russell
Pyro-ma-ni-yak
5072 Posts |
Posted - 2010-08-13 : 13:48:50
|
| [code]-- records in t2 not in t1SELECT t1.*FROM Table1 t1LEFT JOIN Table2 t2On t1.VehicleId = t2.VehicleIdWHERE t2.VehicleId is NULL-- records in t2 not in t1SELECT t2.*FROM Table2 t2LEFT JOIN Table1 t1On t1.VehicleId = t2.VehicleIdWHERE t1.VehicleId is NULL-- records in both but std dev is differentSELECT *FROM Table1 t1JOIN Table2 t2On t1.VehicleId = t2.VehicleIdWHERE t1.stddev <> t2.stddev-- All in one shotSELECT *FROM Table1 t1FULL OUTER JOIN Table2 t2On t1.VehicleId = t2.VehicleIdWHERE t1.vehicleid is nullOR t2.VehicleId is NULLOR t1.stddev <> t2.stddev[/code] |
 |
|
|
|
|
|