Help on muliple table queries

  • Thread starter Thread starter Natalie
  • Start date Start date
N

Natalie

Hi all,
I wonder if you can help. I have 5 tables of data with the same column names.
I want to run a query which includes all records from all tables within a
certain time period using a from/to date.

Is this possible/simple, and how do I do it!!
Thanks
Natalie
 
Hello Natalie.

Natalie said:
Hi all,
I wonder if you can help. I have 5 tables of data with the same
column names. I want to run a query which includes all records from
all tables within a certain time period using a from/to date.

Is this possible/simple, and how do I do it!!

Supposed that your tables were named MyTable1, ... MyTable5 and the
date/time column was named DateCol, you could do the following:
Create a new blank query. Close the add table window without adding
any table. Switch to the SQL view of the query and enter something
like the following:

PARAMETERS [From Date] DateTime, [To Date] DateTime;
SELECT * FROM MyTable1 WHERE DateCol BETWEEN [From Date] AND [To Date]
UNION ALL
SELECT * FROM MyTable2 WHERE DateCol BETWEEN [From Date] AND [To Date]
UNION ALL
SELECT * FROM MyTable3 WHERE DateCol BETWEEN [From Date] AND [To Date]
UNION ALL
SELECT * FROM MyTable4 WHERE DateCol BETWEEN [From Date] AND [To Date]
UNION ALL
SELECT * FROM MyTable5 WHERE DateCol BETWEEN [From Date] AND [To Date];
 
Back
Top