473,805 Members | 2,077 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query across three history tables

RLN
Re: Access 2000

I have three history tables.
Each table contains 3 years worth of data.
All three tables have a date field in them (and autonum field).
Each table has the potential to contain over 100K rows each.
A common request the user receives is a request to pull all data written
in a given month. I need to write some sort of union query across all
three tables that would pull data for, say, only the month of December
of all nine years.

I got a union query to work with two tables.
How do I do it with three or more tables?

Thanks for the assistance.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #1
7 3659
You should be able top just add more UNION statements:

SELECT Fld1, Fld2 FROM tbl1
UNION SELECT Fld1, Fld2 FROM tbl2
UNION SELECT Fld1, Fld2 FROM tbl3;
etc.....
On 23 Jun 2004 21:10:36 GMT, RLN <no*******@devd ex.com> wrote:
Re: Access 2000

I have three history tables.
Each table contains 3 years worth of data.
All three tables have a date field in them (and autonum field).
Each table has the potential to contain over 100K rows each.
A common request the user receives is a request to pull all data written
in a given month. I need to write some sort of union query across all
three tables that would pull data for, say, only the month of December
of all nine years.

I got a union query to work with two tables.
How do I do it with three or more tables?

Thanks for the assistance.
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 13 '05 #2
I got a union query to work with two tables.
How do I do it with three or more tables?

Thanks for the assistance.


SELECT field1, field2
FROM table1
UNION ALL
SELECT field1, field2
FROM table1...

will give you ALL the records, including duplicates (should there be any).

using a plain UNION will give you ONLY unique records.
Nov 13 '05 #3
RLN
Now I would like to take this union query a step further.
In each of these three test tables are two rows, each has a date in the
month of December, and TblTest2004 is the only table with 3 rows for the
month of March.
How can I pull just those 9 rows out of all three tables?
(6 total for 12/2003, 2004 & 2005, then also 3 for March in 2004 only?
The trick is that when this goes live, the user might not always know
what year the March data is located, but will only have the month.
I tried using the 'month' function as listed below, to no avail.
Suggestions?

SELECT ccdate, comments
FROM TblTest2003
UNION
SELECT ccdate, comments
FROM TblTest2004
UNION
SELECT ccdate, comments
FROM TblTest2005
where month(ccdate) =12 or month(ccdate = 3)

(I wasn't sure how to qualify the ccdate field from TblTest2003, ccdate
from TblTest2004, etc..etc.)

Suggestions are welcome.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #4
> In each of these three test tables are two rows, each has a date in the
month of December, and TblTest2004 is the only table with 3 rows for the
month of March.
How can I pull just those 9 rows out of all three tables?
(6 total for 12/2003, 2004 & 2005, then also 3 for March in 2004 only?
The trick is that when this goes live, the user might not always know
what year the March data is located, but will only have the month.
I tried using the 'month' function as listed below, to no avail.
Suggestions?

SELECT ccdate, comments
FROM TblTest2003
UNION
SELECT ccdate, comments
FROM TblTest2004
UNION
SELECT ccdate, comments
FROM TblTest2005
where month(ccdate) =12 or month(ccdate = 3)

(I wasn't sure how to qualify the ccdate field from TblTest2003, ccdate
from TblTest2004, etc..etc.)


If you are filtering the whole dataset (the result of the unions),
build another query on this one which does the filtering. otherwise,
you need to include a WHERE clause for *each* select statement in your
union query.
Nov 13 '05 #5
SELECT ccdate, comments
FROM TblTest2003 where ccdate = #12/03/04#
UNION
SELECT ccdate, comments
FROM TblTest2004 where ccdate = #12/03/04#
UNION
SELECT ccdate, comments
FROM TblTest2005 where ccdate =#12/04/05#;

This union query runs, but using the Query Designer (SQL view)
I need to try two other flavors of this query:
1. check to see if the month is 03 (March) or 12 (December)
(I tried "month(ccdate)" , which did not work.

2. set this query up to launch two dialogs: "a begin month" and an "end
month", then pulls all the history for that range of months in between.
(user inputs "4", then "9", the query would pull all data for April thru
September for all three years.

---------------
Thanks.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #6
> This union query runs, but using the Query Designer (SQL view)
I need to try two other flavors of this query:
1. check to see if the month is 03 (March) or 12 (December)
(I tried "month(ccdate)" , which did not work.
SELECT Table4.SomeDate , Month([SomeDate]) AS MonthNo
FROM Table4
WHERE (((Month([SomeDate])) In (3,12)));
2. set this query up to launch two dialogs: "a begin month" and an "end
month", then pulls all the history for that range of months in between.
(user inputs "4", then "9", the query would pull all data for April thru
September for all three years.

SELECT Table4.SomeDate , Month([SomeDate]) AS MonthNo
FROM Table4
WHERE (((Month([SomeDate])) Between [Enter a begin month:] And [Enter
an end month:]));
Nov 13 '05 #7

I am working to refine the selection process so that the date range gets
pulled across all three tables.
So far the tests are looking ok.
---------------
Thanks.

*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2660
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I need to be able to do a search for specific tickets withing price ranges, different locations within the theaters, etc. etc. My problem is in the search one of the criteria is to search for a group of seats together. For example let's say...
0
2296
by: David | last post by:
This might be a report question but I think it is more a query issue than a report. I am a novice at bothAccess reporting and queries and have been struggling to build the following. (Note using Access2000) I have three tables (that are part of a different program so I can't change their structure). They are Units, Streams, and _Strms. Units contains info about various units. The fields within Units that I am interested in are ID,...
1
2491
by: NA | last post by:
Is it possible to have adjustable tables (not Access tables per se) but those in Ms Word or Excel based on nexted forms three deep? In other words, if I have a main form, Repair History, both the row and columns would grow accordingly. Column Heading: Parts Row Heading: Repair Description In this case, I may only know 25% of the parts when creating the table after
3
1907
by: Ron Nolan | last post by:
I have a large application that contains lots and lots of financial history data. The history data is currently set up in a table called 'TblHist' that exists inside each of these three .mdb files. Each .mdb has approx. 175k rows in its history table. HistData2001.mdb - history data in TblHist for year 2001 HistData2002.mdb - history data in TblHist for year 2002 HistData2003.mdb - history data in TblHist for year 2003. (All .mdb's...
6
29946
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access newsgroups, the access support centre, I can seem to find no similar situation. I am not using any references, or VBA at all in the first place. I am trying to set up a simple (or so I thought) query to work with the text of two tables. ...
3
30293
by: mkjets | last post by:
I have worked for hours on trying to find a solution and have not figured it out. I am working in Access 2003. I need to create a query that takes values from 1 table and displays them in multiple fields. I don't have the option of changing the structure of the existing tables because I am importing them from a separate data source on a regular basis. I also need to use a query instead of a form because I then need to be able to export...
0
1257
by: Nyh | last post by:
I tried to explain the best I can but it is very difficult to do. Here it goes. I have three history tables. Teacher, student and school. School and teacher, and school and student are linked together. I need to make a query that makes in one query a temporary table that list all the students that had a teacher change at some given date in the past. For example: If I give the query the following date 01/01/2007 it needs to give me all...
4
1949
by: pokerboy801 | last post by:
OK, I will try to explain this as clearly and as concise as possible. I am using Access, which has three MS Excel Linked tables, to store call center metrics for reps. My Excel workbook has three separate worksheets, all linked to Access. I have a query that performs some minor calculations, not to hard, and will be ued to drive a report. Here is my problem, I only have about 14 rows of data in each table as we only have three reps. ...
1
1984
by: Andy_Khosravi | last post by:
Background: Access 2003 (converted from A97 DB recently), database is split into FE/BE with the FE residing on client machine. I've got a question about how I can possibly optimize a query I've built. This may seem relatively straight forward to some of you more experienced programmers, but I'm almost entirely self-taught. This means that I have some gaps in my knowledge and sometimes go about doing things the hard way never knowing...
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10609
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10360
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10366
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9185
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3845
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.