I want to retrieve the bottom 10 results from a sql server table. I want them to be the last 10 records that were inserted, how can I do this ?
I want to write select bottom 10 * from mytable
however this does not exist (afaik).
I want the last 10 rows inserted. There is no timestamp.
You can reverse the ordering by using DESC instead of ASC at the end of your query.
SQL SELECT TOP statement vs ROW_NUMBER function ROW_NUMBER function helps to give temporary numbers to the result set of the query and it can be also used instead of the TOP clauses.
The ORDER BY statement in SQL is used to sort the fetched data in either ascending or descending according to one or more columns. By default ORDER BY sorts the data in ascending order. We can use the keyword DESC to sort the data in descending order and the keyword ASC to sort in ascending order.
In SQL Server if you don't specify an order then you may get either an index scan or an allocation ordered scan for example. Plus also you might encounter the "advanced scanning" / merry-go-round scanning feature.
You can't.
There is no guarantee at all that the last 10 records returned by select * from mytable
will be the last 10 inserted. There is no default ordering that is used.
You need an ORDER BY
on an appropriate column reflecting insert order.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With