opposite of “top” in sql server, without using order by, there are no keys/indices

前端 未结 5 1353
孤街浪徒
孤街浪徒 2021-01-18 06:14

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

5条回答
  •  迷失自我
    2021-01-18 06:46

    You can do it using a trigger.

    Save the PKs for the just-inserted row in an audit table, along with an increasing index of some kind (identity is probably enough). Delete the oldest when there are more than 10 rows.

    Then join the audit table to the original table to get the full 10 rows.

提交回复
热议问题