Results 1 to 6 of 6
  1. #1
    apk19 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    30

    Two joins in a report

    Hi all

    Been stuck joining a couple of tables and showing related fields in a report. I have two groups: Applicants and Sponsors. Records in each can deposit money into one account recorded as tblTrustAccount. When I run a report, only the Applicant's funds show, and I cannot join a "Trading Name" field from the Sponsor's table. I only want to show the report when there is any balance other than zero. For Applicants I want to show their names, ID and amount. For Sponsors, their Trading Names, ID, and amount.

    SQL is currently:

    SELECT tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName, Sum(tblTrustAccount.Amount) AS SumOfAmount
    FROM Applicants INNER JOIN tblTrustAccount ON Applicants.ClientID = tblTrustAccount.ClientID
    GROUP BY tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName
    HAVING (((Sum(tblTrustAccount.Amount))<>0));

    Obviously, the above is incomplete. I believe I need a separate join for Sponsors, but do not know how to do this. When I change the FROM clause to tblTrustAccount to add a second join, I get zero results:

    SELECT tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName, Sum(tblTrustAccount.Amount) AS SumOfAmount


    FROM (tblTrustAccount INNER JOIN Applicants ON Applicants.ClientID = tblTrustAccount.ClientID) INNER JOIN Sponsor ON Sponsor.SponsorID = tblTrustAccount.SponsorID
    GROUP BY tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName
    HAVING (((Sum(tblTrustAccount.Amount))<>0));

    Assistance greatly appreciated.

  2. #2
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    implication is you don't have any sponsor records with a matching ID in tblTrustAccount

    try changing the second join to a left join - right click on join line and select 'include all records from tblTrustAccounts...'

  3. #3
    AccessToGo is offline Novice
    Windows 10 Access 2007
    Join Date
    May 2018
    Location
    UK
    Posts
    15
    Hi, It sounds like a UNION would do the trick...
    In new query SQL view
    SELECT [LastName] & " " & [GivenName], [ID], [amount] FROM [Applicant]
    UNION ALL
    SELECT [TradingName], [ID], [amount] FROM [Sponsor]
    ORDER BY 1

    Plus whatever WHERE conditions on each should limit results

    Hope I've understood your question.

    Regards
    Chris

  4. #4
    apk19 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    30
    Quote Originally Posted by Ajax View Post
    implication is you don't have any sponsor records with a matching ID in tblTrustAccount

    try changing the second join to a left join - right click on join line and select 'include all records from tblTrustAccounts...'
    LEFT JOIN seems to have solved the issue of the disappearing results, however, the Sponsor's number's don't show. Currently have:

    SELECT tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName, Sum(tblTrustAccount.Amount) AS SumOfAmount
    FROM (tblTrustAccount INNER JOIN Applicants ON tblTrustAccount.ClientID = Applicants.ClientID) LEFT JOIN Sponsor ON tblTrustAccount.SponsorID = Sponsor.SponsorID
    GROUP BY tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, tblTrustAccount.SponsorID, Sponsor.TradingName
    HAVING (((Sum(tblTrustAccount.Amount))<>0));

  5. #5
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,411
    if by sponsor number you mean sponserid, it wont appear if it doesn't exist - or you've hidden the column. If this is still an issue, post some data from your tables and show the relationships

  6. #6
    apk19 is offline Advanced Beginner
    Windows 8 Access 2013
    Join Date
    May 2015
    Posts
    30
    Solved it. My report design was flawed. Instead of attempting to combine two joins, it was far easier to combine two reports.

    Report 1:
    SELECT tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName, Sum(tblTrustAccount.Amount) AS SumOfAmount
    FROM tblTrustAccount INNER JOIN Applicants ON tblTrustAccount.ClientID = Applicants.ClientID
    GROUP BY tblTrustAccount.ClientID, Applicants.GivenNames, Applicants.LastName
    HAVING (((Sum(tblTrustAccount.Amount))<>0));


    Report 2:
    SELECT tblTrustAccount.SponsorID, Sponsor.TradingName, Sum(tblTrustAccount.Amount) AS SumOfAmount
    FROM tblTrustAccount INNER JOIN Sponsor ON tblTrustAccount.SponsorID = Sponsor.SponsorID
    GROUP BY tblTrustAccount.SponsorID, Sponsor.TradingName
    HAVING (((Sum(tblTrustAccount.Amount))<>0));

    Simply added both reports into another report. Had a total for both as well.

    Silly me!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Joins
    By Abacus1234 in forum Queries
    Replies: 5
    Last Post: 08-08-2016, 09:07 AM
  2. Query for Joins
    By sireesha in forum Queries
    Replies: 4
    Last Post: 07-15-2013, 08:27 AM
  3. mutiple joins
    By mothermugger in forum Queries
    Replies: 1
    Last Post: 11-15-2011, 04:06 PM
  4. Joins
    By jlgray0127 in forum Forms
    Replies: 2
    Last Post: 11-11-2011, 05:04 PM
  5. Need Help with Joins
    By usa_dreamer2002 in forum Queries
    Replies: 3
    Last Post: 01-31-2011, 10:58 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums