Results 1 to 4 of 4
  1. #1
    domivax is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    7

    Query DMax

    Hi Everybody,

    I have the following table :

    Table: tbl_Global

    Id CountryId CountyName CountryDate


    __________________________________________________ ___
    1 1 United Kingdom 13.03.2014
    2 1 United Kingdom 02.03.2011
    3 1 United Kingdom 03.04.2010
    4 2 France 01.02.2012
    5 2 France 03.03.2014
    6 2 France 09.09.2010
    7 2 France 08.04.2008
    8 3 Swizterland 09.08.2009
    9 4 Belgium 15.12.2013
    10 4 Belgium 11.08.2011
    11 5 Spain 23.08.2011
    12 5 Spain 25.04.2014


    I have a problem with the function DMax.

    I would like to obtain a query with one record by country with the more recent date (see following query result)

    My function in the sql_Global: Result: DMax("CountryDate","tbl_Global","CountryId")


    Query: sql_Global

    Id CountryId CountryName CountryDate
    __________________________________________________ ___
    1 1 United Kingdom 13.03.2014
    5 2 France 03.03.2014
    8 3 Swizterland 09.08.2009
    9 4 Belgium 15.12.2013
    12 5 Spain 25.04.2014


    and the result is the following:


    Id CountryId CountryName CountryDate
    __________________________________________________ ___
    1 1 United Kingdom 25.04.2014
    2 1 United Kingdom 25.04.2014
    3 1 United Kingdom 25.04.2014
    4 2 France 25.04.2014
    5 2 France 25.04.2014
    6 2 France 25.04.2014
    7 2 France 25.04.2014
    8 3 Swizterland 25.04.2014
    9 4 Belgium 25.04.2014
    10 4 Belgium 25.04.2014
    11 5 Spain 25.04.2014
    12 5 Spain 25.04.2014


    Thank you very much for your help.
    Best Regards,
    Xavier

  2. #2
    amrut is offline Expert
    Windows 7 64bit Access 2010 32bit
    Join Date
    Jun 2012
    Location
    India
    Posts
    616
    Use aggregate query and not DMax for this purpose. See here ( last example) http://www.techonthenet.com/sql/group_by.php and here too http://msdn.microsoft.com/en-us/libr...ice.12%29.aspx

  3. #3
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    Hi -

    It might not be as easy as it looks - if you need to have the ID value included in the query results, a simple aggregate query as suggested by Amrut won't work. Including ID in the "Group By" clause effectively results in no grouping at all, since ID is unique in each record.

    John

  4. #4
    domivax is offline Novice
    Windows 7 64bit Access 2013
    Join Date
    Apr 2014
    Posts
    7
    Thank you both for your answers,

    But John, you’re right and it would have been too easy, I also need in my request for my ID records to use them in another query.

    Best Regards,

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

Similar Threads

  1. dmax value
    By sdel_nevo in forum Programming
    Replies: 2
    Last Post: 09-12-2013, 04:14 AM
  2. Use DMAX in query
    By sarahjh in forum Queries
    Replies: 1
    Last Post: 02-13-2013, 02:49 PM
  3. DMAX in VBA
    By Meanfish in forum Access
    Replies: 1
    Last Post: 11-03-2012, 11:06 AM
  4. Replies: 6
    Last Post: 07-24-2012, 03:02 PM
  5. append query: dlookup or dmax problem
    By jeffr27 in forum Queries
    Replies: 1
    Last Post: 05-10-2011, 09:25 AM

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