Strange SELECT Top 1

  • Lets say I have 10 records with and ID and DateTime Field Such as Below

    ID DateTime

    1 '06/25/2008 12:00:00 AM'

    2 '06/25/2008 12:00:00 AM'

    3 '06/25/2008 12:00:00 AM'

    4 '06/25/2008 12:00:00 AM'

    5 '06/25/2008 12:00:00 AM'

    6 '06/25/2008 12:00:00 AM'

    7 '06/25/2008 12:00:00 AM'

    8 '06/25/2008 12:00:00 AM'

    9 '06/25/2008 12:00:00 AM'

    10 '06/25/2008 12:00:00 AM'

    When I run the Query below:

    SELECT TOP 1 ID FROM Table

    ORDER BY DateTime (Tried both ASC and DESC)

    I get 2

    When I run the Query this way:

    SELECT TOP 1 ID FROM Table

    I Get 1 as expected

    With the SELECT TOP 1 and ORDER BY Clause I never get 1 back what am I missing??

  • every row has the same time setting, so ANY of the rows could be returned in a

    SELECT TOP 1...ORDER BY [DateTime]

    There's no guarantee which row would be pulled.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

Viewing 2 posts - 1 through 1 (of 1 total)

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