Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Location
    helsinki, Finland
    Posts
    2

    Unanswered: Selecting last n from table

    Does anybody know how you can select bottom n entries from a table?

    I can't believe there would be "select top n" function but no "select bottom n" one...

    Thanks for your help!

  2. #2
    Join Date
    Nov 2002
    Posts
    23
    Try this link, seems to explain it pretty well....

    http://www.experts-exchange.com/Data..._20300025.html

  3. #3
    Join Date
    Dec 2001
    Location
    Toronto, Canada
    Posts
    335
    Could you not just reorder the data in descending order to get the bottom.

    Top

    SELECT top 10 *
    from myTable
    order by primaryKey

    Bottom

    SELECT top 10 *
    from myTable
    order by primaryKey desc
    MCDBA

  4. #4
    Join Date
    Nov 2002
    Location
    helsinki, Finland
    Posts
    2
    Originally posted by achorozy
    Could you not just reorder the data in descending order to get the bottom.

    Top

    SELECT top 10 *
    from myTable
    order by primaryKey

    Bottom

    SELECT top 10 *
    from myTable
    order by primaryKey desc
    Yes, but what if I don't have a promary key?

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    you're right, the table does not have to have a primary key, but in order for "top" to work, you have to sort by some column

    what column would you like to sort by? that's what goes into the "top N" query


    rudy

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •