日期:2014-05-18  浏览次数:20407 次

请问高手:Oracle PSQL中的Intersect在SQL200 TSQL中有相应的实现吗?
PSQL语法中的两个运算:

intersect运算   
返回查询结果中相同的部分   

minus运算   
返回在第一个查询结果中与第二个查询结果不相同的那部分行记录。

但是SQL2000中,intersect只是个保留关键字,minus更是没有.

请问,在SQL2000中是否有这两个运算的实现?

------解决方案--------------------
--如果表中没有text、ntext、image、cursor ,可以考虑使用checksum(),如:


--A中有,而B中没有的数据:

select *
from A
where checksum(*) not in (select checksum(*) from B)


--A、B中都有的数据

select *
from A
where checksum(*) in (select checksum(*) from B)

------解决方案--------------------
--如果查但个字段,用

假设表A和表B都只有两个字段id,name
如何用一句SQL返回表A中存在的id,name结果集而在表B中不存在的id,name结果集

select A.* from A left join B on A.id=B.id and A.name=B.name where B.id is null

select * from A where not exists(select top 1 * from B where A.ID=B.ID)

这两个都可以.


--如果查所有字段,前提:表中不能有text、ntext、image、cursor 数据类型的字段。

用CheckSum()最简单:

select * from A where checksum(*) not in (select checksum(*) from B)