Results 1 to 4 of 4
  1. #1
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29

    Problem with multiple table updating query

    I have got two tables:

    Person(ID,Name,LastBuy,Price_Sum)
    Sales(ID,Person_ID,Date,Price)



    There is a relationship between Person.ID and Sales.Person_ID. Now I need to write a query in order to calculate sum of Price field for every person and update result into the Person.Price_Sum field, Then just find the latest buy of everyone through Sales.Date and update into the Person.Lastbuy.
    That sounds complex, I would be really grateful if someone helps me.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Why save calculated data? Saving calculated data, especially aggregate calcs, is usually a bad idea. Since it must be calculated in order to save it, why bother with the extra and complicated step - just run the calculation whenever needed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    fekrinejat is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    29
    Thanks, but what about having calculated fields in Person table which going to be changed whenever data changes on Sales Table ?
    Would you guide me by a real query code for better understanding ?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    The sum calculation and determining latest date are easy and basic Access functionality. Use Query designer to join the two tables. Use that query as the basis for further data manipulation. Can either do a GROUP BY (aggregate) query with Sum of Price field and Max of Date field or build a report using Grouping & Sorting with aggregate calcs. Report will allow display of detail records as well as summary calcs in group header/footer.

    GTW, advise not to use reserved words as names. Date is a reserved word.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 3
    Last Post: 08-22-2012, 03:51 PM
  2. Replies: 6
    Last Post: 05-10-2012, 08:20 PM
  3. Replies: 2
    Last Post: 03-27-2012, 01:02 PM
  4. Replies: 1
    Last Post: 11-05-2010, 04:51 AM
  5. Problem updating from within a query.
    By Frank Nye in forum Queries
    Replies: 5
    Last Post: 10-14-2009, 10:33 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