【发布时间】:2013-10-08 12:18:35
【问题描述】:
有没有办法让两张桌子合二为一?我有两个相同的表,唯一的区别是一个包含最近的数据,另一个包含旧数据。有没有办法做这样的事情?
select *
from customers a,
(rentals union archrentals) r
where a.serno = r.custserno
and r.rentaldate > YYYYMMDD;
【问题讨论】:
有没有办法让两张桌子合二为一?我有两个相同的表,唯一的区别是一个包含最近的数据,另一个包含旧数据。有没有办法做这样的事情?
select *
from customers a,
(rentals union archrentals) r
where a.serno = r.custserno
and r.rentaldate > YYYYMMDD;
【问题讨论】:
为什么不创建这样的视图?
CREATE VIEW v_allRentals
AS
SELECT * form rentals
UNION ALL
SELECT * FROM archrentals
通过这种方式,您可以使用 v_allRentals 而不必担心每次创建查询时都会忘记旧查询。
谢谢, 粘液
【讨论】:
使用临时表
select *
INTO #allcustomers
from customers a,
(rentals union archrentals) r
where a.serno = r.custserno
and r.rentaldate > YYYYMMDD;
那么就可以使用 temptable 来查询结果了。
【讨论】: