Results 1 to 3 of 3

Thread: Query problem

  1. #1
    Join Date
    Aug 2009
    Posts
    37

    Unanswered: Query problem

    Hi,
    eid date day
    1 1/1/2009 5
    1 2/2/2009 7
    2 4/5/2009 8
    2 5/5/2009 9

    i want like this
    eid date day

    1 2/2/2009 7
    2 5/5/2009 9

    i want distinct values like aboue results.

    Thanks

  2. #2
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    Code:
    WITH cte AS
    (SELECT eid, date, day,
           ROW_NUMBER() (PARTITION OVER eid ORDER BY date DESC) as RowNum
    FROM MyTAble)
    SELECT eid, date, day
    FROM cte
    WHERE RowNum = 1
    This will work from SQL Server 2005 and up.
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

  3. #3
    Join Date
    Aug 2009
    Posts
    37
    thanks wim
    its working fine

Posting Permissions

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