user1297532
user1297532

Reputation:

Let two table act as one

Is there any way to let two tables act as one? I have two identical tables, the only difference is that one contains recent data and the other one older data. Is there any way to do something like this?

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

Upvotes: 0

Views: 116

Answers (2)

MyNameIsSlimChady
MyNameIsSlimChady

Reputation: 21

Use a temporary table

select * 

INTO #allcustomers

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

then you can use the temptable to query the results.

Upvotes: 0

mucio
mucio

Reputation: 7137

Why don't you create a view like this?

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

In this way you can use v_allRentals without worrying every time you create a query that you are forgetting the old ones.

Thanks, Mucio

Upvotes: 1

Related Questions