Selecting the TOP x rows less one

  • I need to create a dataset (working with ASP.NET) based on a selected retrieving the 6 most recent records (based on a date) after the most recent.

    In other words:

    2006/01/25 9PM20

    2006/01/24 3PM30

    2006/01/24 9AM20

    2006/01/23 9PM20

    2006/01/22 9PM20

    2006/01/21 9PM20

    2006/01/20 9PM20

    It should retrieve all rows except 2006/01/25 9PM20

    Any idea on how I should write the SQL Statement ?


    Jean-Luc
    www.corobori.com

  • Something like this?

    select top 6 myfield

    from mytable

    where mytable.myfield <> (select max(myfield)

                              from mytable)

    order by myfield

     

  • Shame on me ! It was so easy

    Thanks


    Jean-Luc
    www.corobori.com

  • Sometimes you can't see the forest because of those damn trees.

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

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