Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

t-sql - bottom 10 records where there is no field to sort by

Status
Not open for further replies.

MontecitoDeb

Programmer
Apr 11, 2012
3
0
0
US
I have a table that has no fields containing unique data. I would like to get the first 10 records entered, i.e. bottom 10 if I could sort by date entered. Again, I have no field that I can sort by. Is this possible?
 
Without some means of identifying them, as far as I'm aware you are, well, stuffed on this one I'm afraid...

Rhys

"Technological progress is like an axe in the hands of a pathological criminal"
"Two things are infinite: the universe and human stupidity; and I'm not sure about the the universe"
Albert Einstein
 
No,
If there is no field(s) that tells you which is the last record, you have no chance to get what you want.


Borislav Borissov
VFP9 SP2, SQL Server
 
If you can sort by date use DESC and TOP 10. If not it is best to think of it as SQL Server not storing data in order other than Primary Key.

djj
The Lord is my shepherd (Psalm 23) - I need someone to lead me!
 
Thank you. As expected. During the season of miracles, I was hoping for one!
 
You could add a new field to your table which defaults to getdate(). This would ensure each row would be "stamped" with the date and time when they're added. This would only work for new records going forward though and there is no way to add this functionality as a backfill.

Something like this would start the stamping though :

Code:
ALTER TABLE tblName
ADD DateAdded datetime2 DEFAULT (GETDATE());

These days I tend to think that all tables should have this, and also a trigger to populate an update field in the case of changes.

Best of luck,

Sid

Instance Manager PRO from Marblefish
Innovative additions for your Business Objects System!
 
Or add a primary key to your table that will uniquely identify each row
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top