Reputation: 13123
I'm working with sql server 2005.
I have a view which sorts its columns according to order date. I call:
SELECT TOP 1 [OrderDate]
FROM [ordersview]
to get the latest time. How do I get the earliest time?
Upvotes: 1
Views: 902
Reputation: 61
I think, this is little bit tricky question.
Every body will say for white is opposite black. And for first is it last.
but when u are not specifying initial order what is really the first.
I think it is internal/vendor specific thing.
So both answers are right ,but actually not answering really your question.
I'm not really mssql-guy but think that your select will return random row (maybe depending on inserting sequence , or same internal db thing like rowId).
And what is opposite for random ?
One more thing is that, ordering is pretty demanding(resource/performance) function , for such thing u should have index on column.
And basically when u are doing select like that u should thing about real paging not only one item .
But then the result will have different order then original one ( so ... )
Upvotes: 0
Reputation: 41549
Use a descending ordering:
select top 1 OrderDate from ordersview order by OrderDate desc
Upvotes: 2