Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to select the newest records

Author  Topic 

dcarva
Posting Yak Master

140 Posts

Posted - 2011-12-08 : 13:02:10
I have a table that I need to select from. However, I need to select out which are the newest and latest records. The table does not have a timestamp column or datetime column specifying when the record was created. Without me adding one, is there a way for me to return the newest records using a select statement? I have a DB2-proficient developer telling me each row should have an accessible timestamp. I am not sure that is correct.

Thanks!

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 13:03:02
do you have an identity (auto-increment) column in your table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2011-12-08 : 13:10:00
No, I wish it did. This is a table on a system that I cannot modify, sadly. Does a row in SQL db have a timestamp that is accessible somehow? I've never heard of one. THANKS!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-08 : 13:30:15
not in sql server unless you add it yourself

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-12-08 : 13:48:32
The physical order of data in a database is meaningless..and your DB2 developer is correct.

EVERY table I design has 4 admin column for our use

ADD_TS
ADD_BY
UPD_TS
UPD_BY

without that, or an Identity column, or some manual incrementing column, you can't tell...post the DDL for kicks



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2011-12-08 : 17:55:50
Ok, many thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-09 : 01:16:55
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -