Non-updatable query due to aggregates (max) (1 Viewer)

mab9

Registered User.
Local time
Today, 16:28
Joined
Oct 25, 2006
Messages
63
Hi,

I'm stumped on this & have been trying to figure it out today. I have two simple tables:

tbl_cost - contains the cost history for a series of items & the dates when that cost goes active

tbl_detail - 2nd table which contains the items number and blank fields for date & cost

I'm looking for a way to run an update query which would bring the max of the date field from tbl_cost into the appropriate items in tbl_detail. I'm struggling with figuring out how to do this since using the Group By/Max(date) in Access turns the query non-updatable. I think I saw somewhere that this can be worked around using SQL sub-queries however I can't get that to work. Help?
 

Attachments

  • max.zip
    9 KB · Views: 99

ByteMyzer

AWF VIP
Local time
Today, 14:28
Joined
May 3, 2004
Messages
1,409
Try the following:
Code:
UPDATE tbl_detail AS T1
INNER JOIN tbl_cost AS T2 ON T1.item=T2.item
SET T1.date=T2.date, T1.cost=T2.cost
WHERE T2.date=
 (SELECT MAX(T3.date)
  FROM tbl_cost AS T3
  WHERE T3.item=T2.item
 )
;
 

jal

Registered User.
Local time
Today, 14:28
Joined
Mar 30, 2007
Messages
1,709
Try the following:
Code:
UPDATE tbl_detail AS T1
INNER JOIN tbl_cost AS T2 ON T1.item=T2.item
SET T1.date=T2.date, T1.cost=T2.cost
WHERE T2.date=
 (SELECT MAX(T3.date)
  FROM tbl_cost AS T3
  WHERE T3.item=T2.item
 )
;

Thanks, ByteMyzer - I don't know about the original poster, but I myself found this info very helpful.
 

Users who are viewing this thread

Top Bottom