473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Combine Queries?

Can someone please help me. I have a feeling I'm making the problem much more complicated than it has to be. I'll start by describing the end goal, then I'll describe my actions to date.

The situation:

You have "tbl_projects" Each project has a primary contact and a secondary contact.

The goal:

View frm_contacts columnar, and for each contact show the Projects where the contact is EITHER the primary OR the secondary contact.

My Actions:

Qry_primproj shows contacts listed as primary on project and the projects id
Qry_secproj shows contact listed as secondary on project and the projects id

How do I set up a query so that it will show ALL contacts, and for each contact, will show the ProjectID for which they are EITHER primary OR secondary contact?

Any info is much appreciated.

Notes: A2K, very limited skill in VB
Sep 19 '07 #1
9 1626
mlcampeau
296 Expert 100+
So you have the two queries working and you are looking to combine them? You could create an Append query. If you post your sql then we can look at it to see if it would be simple to combine the two queries into one.
Sep 19 '07 #2
Qry_BrokersLoans

SELECT [Tbl_Contacts].[ContactID], [Tbl_Contacts].[Prefix], [Tbl_Contacts].[FirstName], [Tbl_Contacts].[MI], [Tbl_Contacts].[LastName], [Tbl_Contacts].[Suffix], [Tbl_Contacts].[CompanyID], [Tbl_Contacts].[Title], [Tbl_Contacts].[MainOfficePhone], [Tbl_Contacts].[MainOfficePhoneX], [Tbl_Contacts].[HomePhone], [Tbl_Contacts].[CellPhone], [Tbl_Contacts].[Fax], [Tbl_Contacts].[Roll], [Tbl_Contacts].[BrokerID], [Tbl_Contacts].[ContactNotes], [Tbl_Loans].[LoanID], [Tbl_Loans].[LoanName], [Tbl_Loans].[LoanType], [Tbl_Loans].[LoanPurpose], [Tbl_Loans].[LoanAmount], [Tbl_Loans].[LoanBroker]
FROM Tbl_Contacts INNER JOIN Tbl_Loans ON [Tbl_Contacts].[ContactID] =[Tbl_Loans].[LoanBroker];


Qry_ClientsLoans

SELECT Tbl_Contacts_1.ContactID, Tbl_Contacts_1.Prefix, Tbl_Contacts_1.FirstName, Tbl_Contacts_1.MI, Tbl_Contacts_1.LastName, Tbl_Contacts_1.Suffix, Tbl_Contacts_1.CompanyID, Tbl_Contacts_1.Title, Tbl_Contacts_1.MainOfficePhone, Tbl_Contacts_1.MainOfficePhoneX, Tbl_Contacts_1.HomePhone, Tbl_Contacts_1.CellPhone, Tbl_Contacts_1.Fax, Tbl_Contacts_1.Roll, Tbl_Contacts_1.ContactNotes, [Tbl_Loans].[LoanID], [Tbl_Loans].[LoanName], [Tbl_Loans].[LoanType], [Tbl_Loans].[LoanPurpose], [Tbl_Loans].[LoanAmount], [Tbl_Loans].[LoanClient]
FROM Tbl_Contacts AS Tbl_Contacts_1 INNER JOIN Tbl_Loans ON Tbl_Contacts_1.ContactID=[Tbl_Loans].[LoanClient];



Tbl_Contacts includes everyone. Tbl_contacts!roll defines if the contacts is a "Broker" or "Client"

The goal is to view the Contact's form page and include ANY loan for which the contact is EITHER the broker OR the client

As you can see, tbl_Loans includes one field for "Broker" where the input will be the contactID, and another field for "Client" where the input will be contactID.

Thanks!
Sep 19 '07 #3
mlcampeau
296 Expert 100+
I don't know what I was thinking when I said Append query. What I meant to say was Union query.
Try:
Expand|Select|Wrap|Line Numbers
  1. SELECT [Tbl_Contacts].[ContactID], [Tbl_Contacts].[Prefix], [Tbl_Contacts].[FirstName], [Tbl_Contacts].[MI], [Tbl_Contacts].[LastName], [Tbl_Contacts].[Suffix], [Tbl_Contacts].[CompanyID], [Tbl_Contacts].[Title], [Tbl_Contacts].[MainOfficePhone], [Tbl_Contacts].[MainOfficePhoneX], [Tbl_Contacts].[HomePhone], [Tbl_Contacts].[CellPhone], [Tbl_Contacts].[Fax], [Tbl_Contacts].[Roll], [Tbl_Contacts].[BrokerID], [Tbl_Contacts].[ContactNotes], [Tbl_Loans].[LoanID], [Tbl_Loans].[LoanName], [Tbl_Loans].[LoanType], [Tbl_Loans].[LoanPurpose], [Tbl_Loans].[LoanAmount], [Tbl_Loans].[LoanBroker]
  2. FROM Tbl_Contacts INNER JOIN Tbl_Loans ON [Tbl_Contacts].[ContactID] =[Tbl_Loans].[LoanBroker]
  3. UNION
  4. SELECT Tbl_Contacts_1.ContactID, Tbl_Contacts_1.Prefix, Tbl_Contacts_1.FirstName, Tbl_Contacts_1.MI, Tbl_Contacts_1.LastName, Tbl_Contacts_1.Suffix, Tbl_Contacts_1.CompanyID, Tbl_Contacts_1.Title, Tbl_Contacts_1.MainOfficePhone, Tbl_Contacts_1.MainOfficePhoneX, Tbl_Contacts_1.HomePhone, Tbl_Contacts_1.CellPhone, Tbl_Contacts_1.Fax, Tbl_Contacts_1.Roll, Tbl_Contacts_1.ContactNotes, [Tbl_Loans].[LoanID], [Tbl_Loans].[LoanName], [Tbl_Loans].[LoanType], [Tbl_Loans].[LoanPurpose], [Tbl_Loans].[LoanAmount], [Tbl_Loans].[LoanClient]
  5. FROM Tbl_Contacts AS Tbl_Contacts_1 INNER JOIN Tbl_Loans ON Tbl_Contacts_1.ContactID=[Tbl_Loans].[LoanClient];
I haven't tested this, but if your above queries worked, then something like this should.
Sep 19 '07 #4
Dude!

You rock!

I didn't use your exact code because it looked like something was missing, and I had to delete an un-matching column from one of the queries, but I had no idea you could UNION two tables/queries like this.

The resulting query is exactly what I wanted and I've used a subform (don't kill me) in the Contacts form that lists loans this contact is associated with.

Excellent.

Thank you.

If you have another suggestion as to how I could or should include this information on the Contact form without using a subform, i'm all ears.
Sep 19 '07 #5
mlcampeau
296 Expert 100+
Dude!

You rock!

I didn't use your exact code because it looked like something was missing, and I had to delete an un-matching column from one of the queries, but I had no idea you could UNION two tables/queries like this.

The resulting query is exactly what I wanted and I've used a subform (don't kill me) in the Contacts form that lists loans this contact is associated with.

Excellent.

Thank you.

If you have another suggestion as to how I could or should include this information on the Contact form without using a subform, i'm all ears.
Yes, I did notice that your one query had an un-matching column, but it was more the idea I was trying to convey. I'm glad you got it to work!
As for the subform part, is your contact form and subform based on the same query?
Sep 19 '07 #6
Yes, I did notice that your one query had an un-matching column, but it was more the idea I was trying to convey. I'm glad you got it to work!
As for the subform part, is your contact form and subform based on the same query?

No... :(

It's a small query with a specific goal in mind. I guess I could use it as part of a larger query, but jumping ahead, the problem I would get to is that I don't know how I would set it up for a one to many. One broker will have many loans. I'd have to list all of the loans with a link to the loan form on the broker's ContactForm (or something like it.) I don't know how to do that without using a tabular subform.

Thoughts?
Sep 19 '07 #7
mlcampeau
296 Expert 100+
I would probably use a subform in this instance. Seems the most logical way to do it. I'm not sure if there's another way. At least not another simple way of doing it. I'm still learning a lot when it comes to Access, so unfortunately, other than using a subform, I have no other ideas.
Sep 19 '07 #8
I would probably use a subform in this instance. Seems the most logical way to do it. I'm not sure if there's another way. At least not another simple way of doing it. I'm still learning a lot when it comes to Access, so unfortunately, other than using a subform, I have no other ideas.

That's fine. Your UNION advice was killer. I can think of so many uses for that. I'm now rethinking redoing about half my tables and queries... thanks a lot...

:)
Sep 19 '07 #9
mlcampeau
296 Expert 100+
That's fine. Your UNION advice was killer. I can think of so many uses for that. I'm now rethinking redoing about half my tables and queries... thanks a lot...

:)
Not a problem! Good luck with the rest of your project!
Sep 19 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Chris Lutka | last post by:
I've been racking my brains all day over this. And I'm not the best at SQL either. I need a query that will produce the following results:...
5
by: Jamie Pittman via AccessMonster.com | last post by:
I have two tables with 5000 entries on them. One is based for regular time with several variables example (employee name, date,time in and out, code, customer, building) I have another table that...
4
by: Jason Gyetko | last post by:
Is there any way to combine these two queries into one? I have tables Item_Master & Kit_Master which are the source tables. Query 2 is using both Item_Master (table) & qryKit1 (query) &...
1
by: Will | last post by:
Hi all I have a table, where there's AutoID, Name of Person (looked up from tblPerson), Name of Dispute (looked up from tblDispute), Date, Details (Memo). What I have is another table that need...
4
by: PlayHard | last post by:
I want my output in two columns like this: C_INCIDENT_TYPE \ TOTAL COUNT How do I combine my two queries to get result. First Query SELECT C_INCIDENT_TYPE, COUNT (*)
46
by: dude88888 | last post by:
Hello I have one query where i get the total number of units for an entire fund say fund 89 has 1000 total units Then i need to find out how much of the total fund each user has say user...
4
by: | last post by:
I have query1 where I set a date range. Query2 is a crosstab query and is based on query1. I don't want the queries to be saved in the mdb but I do want them to be run in VBA using a querystring. If...
1
by: csolomon | last post by:
Hello: I am using two queries to get one result set. The issue is, I return no data when I combine them into one query. I have listed both queries, as well as the 3rd query that shows them...
2
by: bips2005 | last post by:
i have got two queries, $sql1 = "select cust_id from customer where comp_name = '$compname'"; $result = $DB->query($sql1); $result->fetchInto($row); $sql = "select expirydate from...
13
by: MNNovice | last post by:
I have three tables, tblAP, tblPayroll and tblAllocation. Each records three separate expenses. All three are related by FK ECHOID, each has common fields such as AccountNo, FundNo, GrantNo,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
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,...
0
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...

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.