Reputation: 281
Please can any one help me in writing a query.
I want to get the last inserted 10 records from a table.
Upvotes: 2
Views: 7151
Reputation: 78185
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;
Upvotes: 1
Reputation: 7138
Assuming your table has a primary key which is an identity column:
Select top 10 * from mytable order by mytable.id desc
Upvotes: 3
Reputation: 1518
It would be something like
SELECT TOP 10 * FROM MyTable ORDER BY MyID DESC
MyID should be the primary key
Upvotes: 3