Use DELETE TOP safely through an ordered CTE, preview oldest rows, apply a supporting index, and remove eligible rows in bounded batches.
TOP N Sort: Why a Small TOP Still Reads the Whole Table
Explain TOP N Sort, compare an indexed ordered access path, and align filter and sort keys before adding indexes for frequent requests.
SQL SERVER – DISTINCT Does Not Guarantee ORDER BY
DISTINCT removes duplicate result rows without guaranteeing their order. My original claim that it always sorts output was incorrect.
ORDER BY a Parameter in SQL Server: CASE, Types and Plans
To ORDER BY a parameter in SQL Server, write one CASE expression for each column and direction. This post builds the procedure, shows the type conversion and DISTINCT errors that trip people up, measures the cost of the sort that CASE forces, and compares OPTION (RECOMPILE) and dynamic SQL.
Does GROUP BY Sort Results? Only ORDER BY Guarantees It
Does GROUP BY sort the rows it returns? No: only ORDER BY guarantees an order. This post builds a small demo, shows one GROUP BY query returning two different orders, and reads the plans that explain why.
OFFSET FETCH in SQL Server: Get Rows 21 to 30 After ORDER BY
OFFSET FETCH reads a block of rows from the middle of a sorted result. The demo returns rows 21 to 30, builds pages from a page number and measures why deep pages cost more. A seek based alternative reads the same two pages every time.
How to Sort a Varchar Column Storing Integers with Order By? – Interview Question of the Week #206
How do you sort a Varchar column storing integers with Order By when you cannot change the datatype? Here are two simple solutions I shared with a developer.







