Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

SQL Query

Options
  • 09-04-2004 4:28pm
    #1
    Closed Accounts Posts: 65 ✭✭


    Does anybody know how to access the last, say 20 rows, of a database?

    I know that the code to access the top 20 rows is:

    select top 30 * from tablename;

    But I just can't fing a way of accessing the bottom rows.

    Thanks for any help.


Comments

  • Registered Users Posts: 640 ✭✭✭Kernel32


    Need more info. What database, access,Oracle, SQL Server, mySQL etc?

    Also, what do you mean by last 20? If you don't have an order by then it normally sorts by PK, could be wrong on that? If its sql server or a db that supports Top then just
    select top 20 * from mytable order by myfield desc

    or if its Oracle use RowNum, mySql has something similar as well.


  • Registered Users Posts: 6,762 ✭✭✭WizZard


    You should just be able to sort by whatever field descending (DESC) and then select the top 20.

    <edit>Doh... Reading other peoples replies might work for me!!</edit>


  • Closed Accounts Posts: 65 ✭✭Lister


    I'll give that a go.

    Thanks.


Advertisement