Max () query problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jim

    Max () query problem

    Say I have a table like this (just for example)

    ID Date Name
    __ ____ _____
    1 1/2/2004 Store A
    2 1/1/2004 Store A
    3 1/3/2004 Store B
    4 1/2/2004 Store B


    Say I wanted to get the rows for the maximum dates for stores A and B
    aka this record set..


    ID Date Name
    __ ____ _____
    1 1/2/2004 Store A
    3 1/3/2004 Store B

    How would I got about doing this in sql?

    thanks

    -Jim
  • David Portas

    #2
    Re: Max () query problem

    SELECT id, date, name
    FROM SomeTable AS T
    WHERE date =
    (SELECT MAX(date)
    FROM SomeTable
    WHERE name = T.name)

    --
    David Portas
    SQL Server MVP
    --


    Comment

    Working...