Results 1 to 4 of 4

Thread: COUNT for MAX

  1. #1
    Join Date
    Apr 2006
    Posts
    178

    MAX by DATE

    for access 2000

    with the following

    Table1

    Id1 | Id2 | Date
    --------------------------
    1 | 2 | 13/08/2004
    1 | 2 | 01/06/2004
    1 | 2 | 05/11/2003
    1 | 2 | 10/06/2004

    2 | 2 | 01/06/2004
    2 | 2 | 20/02/2006
    2 | 2 | 13/08/2004
    2 | 2 | 10/06/2004
    2 | 2 | 05/11/2003



    I need Distinct Id1 and Id2 for MAX(Date)
    1 | 2 | 13/08/2004
    2 | 2 | 20/02/2006



    thank you for helping
    Last edited by anselme; 02-15-2007 at 09:41 AM.

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    For the data you've provided, you can just do this:

    SELECT id1, id2, CONVERT(varchar(10), MAX(CONVERT(datetime, date)), 103)
    FROM Table1 GROUP BY id1, id2

    But I suspect you need something like this instead:

    SELECT A.id1, A.id2, B.MaxDate
    FROM Table1 AS A
    JOIN
    (SELECT id1, CONVERT(varchar(10), MAX(CONVERT(datetime, date)), 103) AS MaxDate
    FROM Table1
    GROUP BY id1) AS B
    ON A.id1 = B.id1 AND A.date = B.MaxDate

  3. #3
    Join Date
    Sep 2005
    Posts
    168
    SELECT MAX(id1) AS id1, MAX(id2) AS id2, MAX(mydate) AS mydate
    FROM mytable
    GROUP BY id1, id2

    --HTH--

  4. #4
    Join Date
    Apr 2006
    Posts
    178
    ok i'll try it tomorrow morning
    thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •