Results 1 to 6 of 6

Thread: Sql Top

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Alberton, Gauteng, South-Africa
    Posts
    48

    Unhappy

    Hey guy's

    I need to get the three most recently entered items from SQL table .. I have a Index field in the table that increments by 1 everytime a new value is entered.

    I tried this
    *******
    Set rsResults = conn.Execute("SELECT TOP 3 Head_Index, Head_Headline, Head_Time FROM Headlines")
    ********

    but all this gives me is the top three values in the table. How can I get the 3 bigest Index values out of the table?

    Thanks in advance!
    ;-)
    Jaco
    South-Africa

  2. #2
    Guest
    If you have an index field that's incremented by 1 for each new record then what you could do is put an ORDER BY clause on your SQL statement to sort descending by your increment field. That way you'd be grabbing the 'top 3' from a reverse sorted list - and in effect be grabbing the 'bottom 3'. Something like:
    Code:
    Set rsResults = conn.Execute("SELECT TOP 3 Head_Index, Head_Headline, Head_Time FROM Headlines ORDER BY YourIncrementedIndexFieldName DESC")
    Paul

  3. #3
    Guest
    add 'order by index' to your statement, that should do the job

    good luck

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Alberton, Gauteng, South-Africa
    Posts
    48

    Talking Schweat!

    Thanks guy's it worked!!!!
    ;-)
    Jaco
    South-Africa

  5. #5
    Guest

    :-(

    I'm a girl!

  6. #6

    Thread Starter
    Member
    Join Date
    Jan 2001
    Location
    Alberton, Gauteng, South-Africa
    Posts
    48

    Talking Oops! Sorry

    Ok then

    Thanks ALL it worked and for the Female programmers out there Have a Good One!!!! :-)

    Cheers
    ;-)
    Jaco
    South-Africa

Posting Permissions

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



Click Here to Expand Forum to Full Width