Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2004
    Location
    Pune,India
    Posts
    94

    Red face Unanswered: Selecting Last 'n' records from Table.

    I was given this query but could not build it successfully.
    can anybody help me out.

    Consider the following scenario:

    we have a table with single field of type Varchar(100).
    we have few hundred records in it.
    we want to retrieve last 'n' records from table.

    i know this is bad idea but we need to have some solution to work it out.
    i'm breaking my head but to no use.

    Please help

  2. #2
    Join Date
    Feb 2004
    Posts
    88
    define "last". Its pretty crucial to the solution.

  3. #3
    Join Date
    Aug 2004
    Location
    Pune,India
    Posts
    94

    Red face Defining 'Last'

    By 'Last' we mean from Bottom of table.

  4. #4
    Join Date
    Jun 2003
    Posts
    269

    Thumbs up

    order of the database has no meaning.u can select last n record based on order of that field(asc or desc).thats it.

    eg:
    select top n filedname from table order by filedname asc

    or u can insert those records into a temp table with identity column and select record from that table order by identity column
    eg:
    Code:
    select rowid = IDENTITY (int, 1, 1),* into #t from urtable
     
    select * from #t order by rowid asc
    Last edited by mallier; 11-17-05 at 07:21. Reason: More solution
    I love cursor,though I never use it.Cos' I dont want to misuse it.
    ----------------------------------------------

    ----cheers
    ----http://mallier.blogspot.com

Posting Permissions

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