读书人

怎么在三个同样schema表中查找

发布时间: 2012-02-14 19:19:19 作者: rapoo

如何在三个同样schema表中查找?
大家好,我的问题如下:

我有三个同样schema的表,假设是T1, T2, T3, 每个都是关于股票信息的,只不过不同的表包含的是不同地区的股票,主键PKey在三个表中都不会有相同的,我想进行这样的查找:

对一个主键,在三个表中查找,肯定能找到一个结果,不过不知道怎么写SQL,哪位教我一下?谢谢。



[解决办法]
select * from (select * from t1 union select * from t2 union select * from t3)t
where t.pkey=值
[解决办法]
select * from t1 where pk=pkvalue
union select * from t2 where pk=pkvalue
union select * from t3 where pk=pkvalue;

读书人网 >SQL Server

热点推荐