473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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.
Jan 15 '14 #1
2 1133
Rabbit
12,516 Expert Mod 8TB
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.
Jan 15 '14 #2
Frinavale
9,735 Expert Mod 8TB
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
Jan 20 '14 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Patrizio | last post by:
Hi All, I've the following table with a PK defined on an IDENTITY column (INSERT_SEQ): CREATE TABLE MYDATA ( MID NUMERIC(19,0) NOT NULL, MYVALUE FLOAT NOT NULL, TIMEKEY ...
2
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. ...
2
by: M Wells | last post by:
Hi All, I need to change a column value in several thousand records in a table and output a list of the record ids of the records I've updated into another table. The table, however, is being...
2
by: dbuchanan | last post by:
Hello, I am using Win forms VB 2003 The form design requires the newest records appear at the top of the DataGrid. I load my form with a stored procedure that orders the records with the...
1
by: Marc | last post by:
Hi, I made a detailsview for inserting records. I also made a gridview for editing and deleting the same records. The keyfield is an autonumbering field in Access (pcnr). My problem is: I can...
24
Coldfire
by: Coldfire | last post by:
hello ppl. I am havin this minor problem that i have not yet figured out lately. I am developing a windows application in VStudio.net 2005 that interacts with an Access DB (with latest MS Jet...
7
by: ebindia0041 | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, Asp.net 1.1 with c# I'm inserting simple records into a table. But one...
7
by: wozza | last post by:
hi I'm a Dreamweaver user who's created a few simple data entry/ registrations forms in my time, but I'm not really a coder (though I can follow instructions and am not afraid to dabble...) - I...
0
by: SiddharthKarnik | last post by:
I have customer ID feild in the Customer master table made in oracle which i am filling with an html form. Now i want to make another html form with the same feild but with a dropdown menu box which...
1
by: charles07 | last post by:
how can i get records by the latest date. ie. select last inserted records. mysql db structure below timestamp method id comment 2009-01-10 getThud 16 "....." 2009-01-10 getFoo 12 "....."...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.