n********6 发帖数: 1511 | 1 请教query,请教比较两个table,找出相同和不同的records
SQL 2005
一个在server 1,一个在server 2。
表结构相同。
表数据不同,有共同拥有的纪录(records),也有各自独有的纪录(records)。
server 1, server 2是 linked server,可以直接query。
table 不大,thousands of records。用于看看到底有什么异同。不考虑performance。
table a, sample:
aid, a_environment, a_description...
1, aaa, abcd,...
1, bbb, xyzn,...
1, ccc, ddeea,...
1, ddd, jdie,...
2, aaa, ...
2, bbb, ...
2, ddd, ...
4, aaa, ...
4, ddd, jjgd,
5, ......
...
table b, sample
bid, b_environment, b_description...
2, aa | m**********2 发帖数: 2252 | 2 left join
performance。
【在 n********6 的大作中提到】 : 请教query,请教比较两个table,找出相同和不同的records : SQL 2005 : 一个在server 1,一个在server 2。 : 表结构相同。 : 表数据不同,有共同拥有的纪录(records),也有各自独有的纪录(records)。 : server 1, server 2是 linked server,可以直接query。 : table 不大,thousands of records。用于看看到底有什么异同。不考虑performance。 : table a, sample: : aid, a_environment, a_description... : 1, aaa, abcd,...
| n********6 发帖数: 1511 | 3 当时做了outer join,但是好像不是所要的结果。还没想清楚到底怎么做。
【在 m**********2 的大作中提到】 : left join : : performance。
| d*******8 发帖数: 3182 | 4 1,先定义一下何为相同何为不同吧。
相同:aid = bid and a_env = b_env and a_desc = b_desc?
2,再确认一下你的思路吧。
你是想用一个宋庆龄 statement来比较在不同的database 色窝中的两个桌子,对吗?
performance。
【在 n********6 的大作中提到】 : 请教query,请教比较两个table,找出相同和不同的records : SQL 2005 : 一个在server 1,一个在server 2。 : 表结构相同。 : 表数据不同,有共同拥有的纪录(records),也有各自独有的纪录(records)。 : server 1, server 2是 linked server,可以直接query。 : table 不大,thousands of records。用于看看到底有什么异同。不考虑performance。 : table a, sample: : aid, a_environment, a_description... : 1, aaa, abcd,...
| n********6 发帖数: 1511 | 5
对。整条记录record完全相同。
不一定。能用就好。当时考虑了outerjoin,把两条记录连起来。
每条记录内aid=bid and a_env = b_env and ...的就是相同的。
排除aid is null and bid is null and 相同的纪录 就是有差异的纪录。后来发现错
了。条件似乎很麻烦。明天上班有空再想。
【在 d*******8 的大作中提到】 : 1,先定义一下何为相同何为不同吧。 : 相同:aid = bid and a_env = b_env and a_desc = b_desc? : 2,再确认一下你的思路吧。 : 你是想用一个宋庆龄 statement来比较在不同的database 色窝中的两个桌子,对吗? : : performance。
| w*******e 发帖数: 1622 | 6 你用binary_Checksum()试试
【在 n********6 的大作中提到】 : : 对。整条记录record完全相同。 : 不一定。能用就好。当时考虑了outerjoin,把两条记录连起来。 : 每条记录内aid=bid and a_env = b_env and ...的就是相同的。 : 排除aid is null and bid is null and 相同的纪录 就是有差异的纪录。后来发现错 : 了。条件似乎很麻烦。明天上班有空再想。
| B*****g 发帖数: 34098 | 7 不考虑performance?
Use minus.
performance。
【在 n********6 的大作中提到】 : 请教query,请教比较两个table,找出相同和不同的records : SQL 2005 : 一个在server 1,一个在server 2。 : 表结构相同。 : 表数据不同,有共同拥有的纪录(records),也有各自独有的纪录(records)。 : server 1, server 2是 linked server,可以直接query。 : table 不大,thousands of records。用于看看到底有什么异同。不考虑performance。 : table a, sample: : aid, a_environment, a_description... : 1, aaa, abcd,...
| b******e 发帖数: 1861 | 8 a not in b
union all
b not in a | n********6 发帖数: 1511 | 9 Minus is the right answer for Oracle. Thank you.
In SQLSERVER, I used INTERSECT and EXCEPT and got the result. EXCEPT is teh
'Minus' in SQL.
【在 B*****g 的大作中提到】 : 不考虑performance? : Use minus. : : performance。
|
|