Page 2 of 2 FirstFirst 12
Results 16 to 17 of 17
  1. #16
    Xipooo's Avatar
    Xipooo is offline Sr. Database Developer
    Windows 8 Access 2013
    Join Date
    Jan 2014
    Location
    Arizona
    Posts
    332


    Quote Originally Posted by pbaldy View Post
    True, but I don't think the original subquery would have worked anyway, with multiple fields in the SELECT and the fact that it could return multiple records. It could have worked if it were joined in the FROM clause, but wasn't necessary in either case. I don't think you can join to it the way you have it (it would need to be in the FROM clause, not the SELECT clause). Plus you've left out the comma too.
    You're right, it needs more cleanup. This looks a bit better.

    Code:
    SELECT  tblCust.Custid, qrygross.[grossreceipts], Max(qrygross.SumOfgrossreceipts) AS [MaxOfSumOfgross receipts]
    FROM (SELECT tblCust.Custid, tblgross.grossreceipts, Sum(tblgross.grossreceipts)AS [SumOfgrossreceipts]
    FROM tblgross LEFT JOIN tblCust ON tblgross.custid = tblCust.custid
    GROUP BY tblCust.Custid, tblgross.grossreceipts, tblCust.costid) as qrygross
    RIGHT JOIN tblCust ON qrygross.custid= tblCust.custid;

  2. #17
    slimjen is offline Expert
    Windows XP Access 2007
    Join Date
    Mar 2010
    Posts
    727
    Ok. I jump for joy a little too soon. I just realized the query you suggested did not Max the SumOfGrossReceipts; but Max(grossreceipts) instead. The results are different. When I tried to change it to Max(SumOfgrossreceipts) I receive the same error I was getting before.

Page 2 of 2 FirstFirst 12
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Subquery
    By Daryl2106 in forum Access
    Replies: 20
    Last Post: 01-13-2013, 07:21 AM
  2. Subquery
    By tomclavil in forum Queries
    Replies: 3
    Last Post: 02-27-2012, 03:05 AM
  3. TOP subquery
    By helpaccess in forum Queries
    Replies: 5
    Last Post: 08-30-2011, 10:28 AM
  4. Subquery sum?
    By anemoskkk in forum Access
    Replies: 0
    Last Post: 04-29-2011, 12:36 PM
  5. Subquery
    By combine21 in forum Queries
    Replies: 2
    Last Post: 09-17-2010, 04:33 PM

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