Quote:
|
quote:"last_update"date is just a sample column name. You can just replace it with the actual column name (the "appropriate date column" you refer to in your post). Sorry, thought that was clear.
|
Fair enough.
The point I was trying to make was that the concept of "recent" has no meaning in SQL unless there is some appropriate column to order by.
A file system typically appends new records to the end of the file; retrieving the last two such records is easy. The concept here of "recent" is inherent in the fact that records are added to the end: the records are implicitly ordered by time.
A relational database is not a file system, so none of these concepts apply (concepts like "record", "end", "file", etc). It is true that some systems may assign a unique row identifier as rows are inserted or updated, but there may be no guarantee that these identifiers are monotonically increasing with respect to time, which is what I interpret "recent" to mean...
You are correct that if an appropriate ordering column exists, that the SQL Server 'TOP' clause is a way to retrieve the most recent rows; there are other ways as well (and you may need them if your RDBMS doesn't implement TOP.)
Jeff Mason
Custom Apps, Inc.
www.custom-apps.com