View Full Version : Tying 3 queries into one.


jnixon
04-22-2002, 02:01 PM
I have 3 different queries pulling from the same table. The reason I used 3 different ones was because I want to sum up some fields under 3 different criteria. I was going to just sort and group on a report, but I can't total it the way I want to, so I thought it would be easier to have the query do it before it hits the report. Anyway, I want to make a final query to pull the three into one so I can put this out to a single report. I would do several subreports but this gets difficult when you need to total up even more info.

Each of the three queries has only one field in common, which is a field that is user-input and filtered through each query under its individual criteria. Several calculations take place in these queries and you end up with 4 calculated fields per query. I want to have 3 rows and 4 columns in the end. But, every time I try to put the three queries on one, it will run but returns no data! These queries work fine by themselves. Can someone help me make this work?

Whew! That was a lot! http://www.access-programmers.co.uk/ubb/smile.gif Hope it's enough info.

jnixon
04-25-2002, 08:07 AM
Okay, I got most of this problem fixed. I realized that I needed to run a few more queries to calculate what I want. However, each query returns a different number of results. It still maintains the same thing in common, which is the [Vendor] field. What I want to do, is to combine all three of these queries and list it by the [Vendor] field. The problem is, one query (Quality) returns 100 records, one (Rechecks) returns 85, and one (TAT) returns 190. I want to list the results by the [Vendor] field from teh (Quality) query, and match up the rest of the queries by that main one. Can anyone help me do this?

Pat Hartman
04-25-2002, 04:27 PM
If the three queries contain the same number of columns in the same order and the data types are consistant, you can use a UNION ALL query to merge the three separate recordsets into one.

jnixon
04-29-2002, 07:49 AM
This isn't working. What I need to do is take 3 scores from these 3 queries and come up with some averages. In the queries, there is one field, Vendor, which is common. A Union Query does bring everything together, but not in a way that I can line it up by Vendor and average the scores.

jnixon
04-29-2002, 07:52 AM
Is there a way I can Union these queries with the coulmns side-by-side sorted by this Vendor field? Sometimes one of the other queries might not have a value to list. I tried running a duplicate query but I can't get it to average it out either.

jnixon
04-29-2002, 08:31 AM
HAHA! I did it. I realized what I was doing wrong and I corrected it. I was able to pull data from the queries by changing the join properties between the queries. That's why I was only getting like 80 records in the first place, which was my original problem. No union query was necessary, I just pulled what I wanted, and went with it. http://www.access-programmers.co.uk/ubb/smile.gif The Access Gods were pleased today.