0

有没有办法让两张桌子合二为一?我有两个相同的表,唯一的区别是一个包含最近的数据,另一个包含旧数据。有没有办法做这样的事情?

select * 
  from customers a, 
       (rentals union archrentals) r
 where a.serno = r.custserno
   and r.rentaldate > YYYYMMDD;
4

2 回答 2

1

你为什么不创建这样的视图?

CREATE VIEW v_allRentals
AS
SELECT * form rentals
UNION ALL
SELECT * FROM archrentals

通过这种方式,您可以使用 v_allRentals 而不必担心每次创建查询时都会忘记旧查询。

谢谢,穆西奥

于 2013-10-08T12:23:43.570 回答
0

使用临时表

select * 

INTO #allcustomers

  from customers a, 
       (rentals union archrentals) r
 where a.serno = r.custserno
   and r.rentaldate > YYYYMMDD;

然后你可以使用 temptable 来查询结果。

于 2013-10-08T14:43:38.327 回答