If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Help on muliple table queries
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 |
#2
|
|||
|
|||
Help on muliple table queries
Hello Natalie.
"Natalie" wrote: 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]; -- Regards, Wolfgang |
Thread Tools | |
Display Modes | |
|
|