开发者

Get last 10 records in SQL Server 2005

Please can any one help me in writing a query.

I want to 开发者_如何学运维get the last inserted 10 records from a table.


It would be something like

SELECT TOP 10 * FROM MyTable ORDER BY MyID DESC

MyID should be the primary key


Assuming your table has a primary key which is an identity column:

Select top 10 * from mytable order by mytable.id desc


Unless you have a field in your table declared like this:

date_putin datetime not null default getdate()

and unless this field can never be written to by a client, you can't. Because there's no row order in a table.

But if you do have this field, and no client can ever write to it, then

select top (10) * from t order by date_putin desc;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜