Results 1 to 3 of 3
  1. #1
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150

    *Help with SQL Max Query with Criteria

    Hi,

    Looking for some help with a pretty basic SQL problem. Rather than use DMax with a query, i'd prefer to open a recordset and do it all in one step. If Access allowed query string in the DMax function then my issue would also be solved.



    Table:

    Code:
    ID          Version
    --------------------------
    A60            5
    A100          1
    A100          2
    A102          1
    A300          1
    A300          2
    A60            1
    A60            2
    A60            3
    I need the max version where the ID equals a variable.

    For example, if ID = A100, query should return record where version = 2 (max)

    If ID = A60, query should return record where version = 5


    Thanks for the help!

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,963
    Perhaps you need TOP 1 nested query. Review http://allenbrowne.com/subquery-01.html#TopN
    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
    ironfelix717 is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2018
    Posts
    150
    Hi, thanks for the reply.

    Nested query would be to much work.

    I found the solution. SQL string should be as follows..

    Code:
    sql = "SELECT table1.ID, Max(table1.Version) AS Version FROM table1 GROUP BY table1.ID HAVING table1.ID= '" & ProcID & "';"

    Regards,

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

Similar Threads

  1. Replies: 2
    Last Post: 04-02-2015, 12:45 PM
  2. Replies: 4
    Last Post: 08-30-2014, 10:23 AM
  3. Replies: 5
    Last Post: 09-20-2012, 03:27 PM
  4. Replies: 5
    Last Post: 08-02-2012, 09:44 AM
  5. Replies: 1
    Last Post: 07-13-2011, 11:00 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