Get the newest inserted 15 records

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Otekpo Emmanuel
    New Member
    • Dec 2013
    • 23

    #1

    Get the newest inserted 15 records

    Good day everybody. I'm designing a chat with asp.net, and everything is working except one.
    I want to retrieve the newest 15 records then delete the old ones. I used count to get the number of records in my table then specify that if count is equal to 20, then, I used sql Top statement to delete the Top 5 messages. But I found that sql server sort whatever is inserted in alphabetical order. And this technique delete both the newest messages. Please, some should tell me how to achieve this. Thanks in advance.
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    Without the query code, it's hard to suggest any thing concrete but you should probably need to use a sort to sort by some sort of timestamp field.

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      If you use a Date type column to store the time that the message was sent, you should be able to use an order by statement to sort the results appropriately.

      -Frinny

      Comment

      Working...