Results 1 to 5 of 5
  1. #1
    Kevin_Spencer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    2

    Is it possible to obtain [Sum] data in a single select query from a related table please?

    Hi everybody



    This my first post and I would be grateful for any help as I have spent ages trying to sort this on my own.

    Is it possible to obtain [Sum] data in a single select query from a related table please?

    My CLIENTS table is related one-to-many to my INVOICE table with each client having up to about 100 invoices.

    I am trying to create a select query using both CLIENT & INVOICE tables to return a single record for each client with a calculated field showing the total invoice amounts for each client taken from the Invoice table?

    Any help would be gratefully appreciated.

    Thank you - Kevin Spencer

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    select tClients.ClientID, Sum(tInvoices.Amt) as Total from tClients,tInvoices where tClients.clientID = tInvoices.ClientID

  3. #3
    Kevin_Spencer is offline Novice
    Windows 10 Access 2016
    Join Date
    Jan 2018
    Posts
    2
    Thank you very much for your reply ranman256

    I've typed:

    select tClients.ID, Sum(tInvoices.Gross) as Total from tClients,tInvoices where tClients.ID = tInvoices.Invoice_ID

    straight into a new field in my query (I'm using Create>Query Design in Access 2016) and I am receiving the following error:

    The syntax of the subquery in this expression is incorrect - check the subquerys syntax and enclose the subquery in parentheses.

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Did you enclose it in parentheses as stated? See here for further information on subqueries: http://allenbrowne.com/subquery-01.html

  5. #5
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    select tClients.ID, Sum(tInvoices.Gross) as Total from tClients,tInvoices where tClients.ID = tInvoices.Invoice_ID
    That looks like it should be the SQL for the whole query, not just one field. Youl also need a group by on TClients.ID.

    Here is the SQL for a query that does almost the exact same thing, except that it has two sums, from my own database:

    SELECT COLLECT.ALBUM, Sum(ITEMS.NUMINSET) AS SumOfNUMINSET, Sum(ITEMS.CATVAL) AS SumOfCATVAL
    FROM ITEMS RIGHT JOIN COLLECT ON ITEMS.COUNTRYNUM = COLLECT.CTRYNUM
    GROUP BY COLLECT.ALBUM
    ORDER BY COLLECT.ALBUM;

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

Similar Threads

  1. Query for mismatch data on a single table
    By JFonz in forum Queries
    Replies: 2
    Last Post: 08-01-2016, 12:20 PM
  2. Replies: 7
    Last Post: 07-02-2012, 10:50 PM
  3. Replies: 1
    Last Post: 08-30-2011, 07:35 AM
  4. Obtain data from another table
    By Suzied in forum Database Design
    Replies: 0
    Last Post: 03-23-2010, 11:52 AM
  5. Table related to multiple tables by single ID
    By MrTumnus in forum Access
    Replies: 1
    Last Post: 11-17-2009, 02:05 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