Combining Queries

R

Rem

Hello, I hope someone can help me with this. Is there any way I am able to
combine several queries to make one querie? I have data in table--from which
I am using queries to extract sales data meeting certain criteria.

Query 1: names of all employees with a referral rate of over 19 referrals a
day.
Query 2: names of all employees with a referral rate of over 15 referrals
but less then 19 referralsa day
Query 3: names of all employees with a referral rate of less then 15
referrals a day.

Then I am taking these three Queries to make a report--
I am getting duplicate values in all my feilds--I only have 16 employee
names but the outcome is like 200 names--all with duplicates. Please let me
know if there is a way to make this work.
 
K

Ken Snell \(MVP\)

Perhaps a UNION query:

SELECT T1.*
FROM Query1 AS T1
UNION
SELECT T2.*
FROM Query2 AS T2
UNION
SELECT T3.*
FROM Query3 AS T3;

The above assumes that you have the same number of fields in all three
queries, and that the first field in all three queries has the same data
type in all three queries, that the second field in all three queries has
the same data type in all three queries, etc.
 
J

John W. Vinson

Thanks,

How would I do this in Access? Or would I have to write a code?

Create a new Query. Select View... SQL from the menu, or choose the SQL icon
from the dropdown tool on the left end of the query design toolbar. Type the
UNION query into the SQL window, using your own query and fieldnames.

John W. Vinson [MVP]
 
D

Dale Fye

Rem,

What does your original data structure look like? I think you could
probably write a single query that does what you are looking for and am
almost certain that we could do it with only two queries.

Dale
 
R

Ron2006

Rem,

What does your original data structure look like? I think you could
probably write a single query that does what you are looking for and am
almost certain that we could do it with only two queries.

Dale
--
Don''t forget to rate the post if it was helpful!

email address is invalid
Please reply to newsgroup only.







- Show quoted text -

It would seem to me that you need at least one other item on each of
those queries. Namely what query it is , because your explanation of
the queries says you are going to get everybody (except employees WITH
19 or employees WITH 15 referrals). If you mistated the criteria then
in reality you are getting everyone so you need only one query. Using
a single query you could then create a "catagory" field with logic
something like

catagory: iif(referraldays>18,"1",iif(referaldays <15,3,2))

and then use orderby Catagory.

Ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top