Max Record

  • Hi,

    I have 2 records in my database Table let say

    Date Status TaskName ProjectName

    Today Completed ABC Test

    Today-2 Pending ABC Test

    Now what i need is depend upon the max date i want the record so i need only 1 row from above sample data.

    Date Status TaskName ProjectName

    Today Completed ABC Test

    I tried

    select Max(Date) from <Table Name>

    Group by Status,TaskName,ProjectName

    But of no use still it gives me the 2 Records.

    Thanks in advance.

    Parth

  • remove status column from your group by!

    ---------------------------------------------------------------------------------

  • then how do i have latest status..??

  • You have to be clear with your test data and expected result. It was very vague information that you are giving! Anyway, if you need the latest status based on the date (latest date) for each task and project from your table, then you would write something like this, (not tested as there is no test data)

    Select * from (Select *, Row_number() OVER (PARTITION BY task,

    Project name order by date desc) as row_no

    FROM urtable) t

    Where row_no = 1

    ---------------------------------------------------------------------------------

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply