Select last N record

  • Can anybody help

    Can i use SELECT statement to

    For example,

    Last 100 records or

    last 10% record

    Thanks

  • There is no bottom command, only top. So, to get the bottom records, you have to sort desc.

    For example:

    Select Top 100 *

    From myTable

    Order By someField DESC


    My blog: SQL Soldier[/url]
    SQL Server Best Practices:
    SQL Server Best Practices
    Twitter: @SQLSoldier
    My book: Pro SQL Server 2008 Mirroring[/url]
    Microsoft Certified Master: SQL Server, Data Platform MVP
    Database Engineer at BlueMountain Capital Management[/url]

  • then i need to add identity field for sorting already. any others ways

    Thanks

  • an identity field seems to be always a good choice (at least as primary key).

    do you want to select the last 10% records added to the table. maybe you have a datetime field when the records has been added?

    Cheers,

    Frank

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

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

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