Results 1 to 2 of 2
  1. #1
    Hiche is offline Novice
    Windows 10 Access 2016
    Join Date
    Feb 2019
    Posts
    2

    Multiple selects

    Hi,
    i have created a queries with multiple selects in the sql, for example:

    select trx_date, client_no, sale_amount,
    (select sum(payment_amount) from receipt where trx_date=trx_date) as payments
    from sales.



    my problem is that the queries in returning payments on date of sales and not returning data if on a date there is a payment but no sales.

    How can i solve this issue.

    Thank you in advance

  2. #2
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,931
    sounds like you are not approaching this the right way.

    think you need a union query of all dates

    QryU
    SELECT trx_date, client_no FROM Sales
    UNION SELECT trx_date, client_no FROM Receipt
    then a aggregate query for each of sales and receipt

    QrySA
    Code:
    SELECT trx_date, client_no, sum(Sale_Amount) as sumSales
    FROM Sales
    GROUP BY trx_date, client_no
    QryRA
    Code:
    SELECT trx_date, client_no, sum(Payment_Amount) as sumReceipts
    FROM Receipt
    GROUP BY trx_date, client_no
    then join together with a left join

    Code:
    SELECT QryU.trx_date, QryU.client_no, sumSales, sumReceipts
    FROM (QryU LEFT JOIN QrySA ON  QryU.trx_date=QrySA.trx_date AND QryU.client_no=QrySA.client_no) LEFT JOIN QryRA ON  QryU.trx_date=QryRA.trx_date AND QryU.client_no=QryRA.client_no

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

Similar Threads

  1. Multiple sub-selects . . .
    By Robeen in forum Queries
    Replies: 4
    Last Post: 08-07-2015, 07:24 AM
  2. Replies: 9
    Last Post: 08-09-2014, 01:32 PM
  3. 4 Selects, 1 Union
    By Perceptus in forum Queries
    Replies: 6
    Last Post: 12-27-2012, 03:46 PM
  4. Chain Selects
    By cff_moiseszaragoza in forum Access
    Replies: 2
    Last Post: 10-27-2011, 09:41 AM
  5. set focus selects all of the text
    By markjkubicki in forum Forms
    Replies: 3
    Last Post: 05-19-2011, 12:20 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