Based on Min Timestamp get ID

  • I have a table where it has column ID ,startDate.and Type

    I want to write a query that based on minimum timestamp I have to get ID .

    Example of data -
    ID                     StartDate                                    Type
    21                2016-08-07 21:31:59.727                Emp
    22                2016-08-07 21:32:03.883                Emp
    23                2016-08-07 21:32:07.930                Emp
    24                2016-08-07 21:32:12.337                Emp
    25                2016-08-07 21:32:15.977                Emp
    26                2016-08-07 21:32:19.447                Emp

    How to get ID based on min time stamp

  • You've been here over 500 times and can't even post an answerable question with proper sample data??? Please read this article and repost.

  • SELECT ID
    FROM #Sample S
    WHERE S.StartDate = (SELECT MIN(sq.StartDate) FROM #Sample sq);

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk


  • SELECT TOP(1) ID
    FROM YourTable
    ORDER BY StartDate DESC;

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

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