Results 1 to 12 of 12
  1. #1
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14

    updateable query with max()

    Hey all,

    I'm having a problem with a query. I'll try to condense it to the basics.

    There's a table A with following fields
    ID (autonumber, unique)
    Selected (boolean)
    Notes (text)

    and a table B with following fields
    ID (integer, not-unique)
    score (integer)

    The tables need to be joined on their ID fields; all records from A need to be shown, from table B the maximum score needs to be sought for each given ID.

    On its face this is not a very difficult query; right now I've solved it with

    SELECT A.ID, A.Selected, A.Notes, C.MaxOfScore


    FROM A LEFT JOIN
    (SELECT ID, Max(Score) AS MaxOfScore
    FROM B
    GROUP BY ID) AS C
    ON A.ID = C.ID
    However, this query is not updatable, and therefore not usable for the application I have in mind.

    Is there a way to create a similar query in which (at least) the Selected field *is* updateable?

    Thanks!

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    See if this link helps at all: http://allenbrowne.com/ser-61.html

  3. #3
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14
    Quote Originally Posted by RuralGuy View Post
    See if this link helps at all: http://allenbrowne.com/ser-61.html
    Hey yes thanks for replying, I actually did already see that, and it made it clear why my alternative solution (using distinct) wasn't working either. I couldn't figure out a way that *does*work, though...

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I'm sorry but my brain cells cannot come up with an alternative for you.

  5. #5
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14
    Thanks anyways!

    Maybe someone else...?

  6. #6
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    You might try smaller queries that are not ambiguous and then use them as the source of your current quest. Often time when you break down the problem into smaller chunks you eliminate any ambiguity and Access can handle it.

  7. #7
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14
    I'm not sure if I understand correctly - you mean saving the inner query separately and referencing it like so:

    qryHelp:
    SELECT ID, Max(Score) AS MaxOfScore
    FROM B
    GROUP BY ID;

    and

    SELECT A.ID, A.Selected, A.Notes, qryHelp.MaxOfScore
    FROM A LEFT JOIN qryHelp
    ON A.ID = qryHelp.ID;

    ?

    That I had already tried too, to no avail. (I think Access just replaces the 'qryHelp' instances with the real thing.)

    But keep those ideas roling!

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I don't see the need for a Join. Make sure your 1st query has all of the fields you need and then create another query based on the 1st quesy with differenf selection criteria.

  9. #9
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14
    I'm not following, sorry.

    Could you give me an example? I need to be able to update only the field values of table A.

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,917
    I'm sorry but I have to go back to my Post #4.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    However, this query is not updatable, and therefore not usable for the application I have in mind.
    Could you describe the application you have in mind?

  12. #12
    ElRudi is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Nov 2011
    Posts
    14
    Thanks orange and RuralGuy for your help.

    I want to use the query as the recordsource for a continuous form, on which the user can see all of the records and change its property (e.g. the notes in a textbox, or the 'selected' property as a checkbox). I use the value of MaxOfScore to colour the background of the continuous form via conditional formatting, so that entries that need special attention are immediately identified by the user.

    Of course the value of MaxOfScore does not need to be changeable, but the values of the fields that are neither grouped nor calculated (i.e., those from table A) do need to be.

    Thanks!

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

Similar Threads

  1. Use updateable query error
    By looloo in forum Queries
    Replies: 8
    Last Post: 09-24-2011, 12:39 AM
  2. Must use updateable query
    By adams.bria in forum Queries
    Replies: 1
    Last Post: 08-29-2011, 10:31 AM
  3. Need Query To Be Updateable
    By robsworld78 in forum Queries
    Replies: 11
    Last Post: 07-17-2011, 09:06 PM
  4. Non-Updateable Query
    By swalsh84 in forum Queries
    Replies: 4
    Last Post: 04-27-2011, 12:39 PM
  5. Operation Must use an Updateable Query
    By Lady_Jane in forum Queries
    Replies: 2
    Last Post: 12-14-2010, 03:02 PM

Tags for this Thread

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