同上:(id2为筛选条件)
T1
id1 id2
1 13
2 3
3 4 T2
id1 id2
1 13
2 5
3 4
查询后得到:
id1 id2
2 3
T1
id1 id2
1 13
2 3
3 4 T2
id1 id2
1 13
2 5
3 4
查询后得到:
id1 id2
2 3
解决方案 »
- SQL Server 数据库执行超时 回滚所有的事务
- SQL2005中怎么样实现这样子的行转列?
- 一个小问题,大家帮帮忙
- 请问sql server 2005中对一个表进行递归查询用 cte怎么处理?
- select top 的问题
- 启动sqlserver2005时,弹出一个空白的警告对话框
- 江湖救急:在SQL server发邮件到Outlook信箱,怎么把内容分行了?
- 存储过程的性能会比批处理的T-SQL语句差吗?
- 一个超难的Sql语句,向Sql高手求救,100分
- 安装SQLSever遇到的问题,求教!
- 如何作c/s型的数据库下载服务器?
- 在提交正常的SQL语句时,IE老是转个不停(无响应)....
insert @t1 values(1,13)
insert @t1 values(2,3)
insert @t1 values(3,4)declare @t2 table(id1 int,id2 int)
insert @t2 values(1,13)
insert @t2 values(2,5)
insert @t2 values(3,4)select t1.* from @t1 t1,@t2 t2 where t1.id1=t2.id1 and t1.id2<>t2.id2
where exists(select id1 from t2 where t2.id1=t1.id1 and t2.id2<>t1.td2)
或
select * from t1
where not exists(select id1 from t2 where t2.id1=t1.id1 and t2.id2=t1.td2)
结果应该是:
id1 id2
2 3
2 5
where id not in (select id1 from t2 where t2.id1=t1.id1 and t2.id2<>t1.td2)
出来的结果会是:
1 13
2 3
2 5
3 4
union
select * from t2 x where not exists (select * from t1 y where y.id1 = x.id1 and y.id2 = x.id2)
insert @t1 values(1,13)
insert @t1 values(2,3)
insert @t1 values(3,4)declare @t2 table(id1 int,id2 int)
insert @t2 values(1,13)
insert @t2 values(2,5)
insert @t2 values(3,4)select x.* from @t1 x where exists (select 1 from @t2 y where (x.id1 = y.id1 and x.id2<>y.id2) or (x.id1 <> y.id1 and x.id2=y.id2))
union all
select y.* from @t2 y where exists (select 1 from @t1 x where (x.id1 = y.id1 and x.id2<>y.id2) or (x.id1 <> y.id1 and x.id2=y.id2))