The ORDER BY clause is used to order SET RESULT in the specified column.
Your query Select TOP 10 * from FooTable ORDER BY X DESC Assuming X is a timestamp, it will not return the last 10 rows inserted. It will return the top 10 rows as stored (in any order) in the database and then will return a result set of 10 such rows in descending order. Therefore, your subquery must be changed to
Select TOP 10 * from (Select * from FooTable ORDER BY DESC) as T
This should meet your first requirement. You can then use this result set as an alias to determine your final sort order.
I hope I understood you correctly when you say: "I'm trying to get the top N records (when ordering with some X columns)"
The machine
source share