Selecting a range from a table is easy in MYSQL. Say you want to bring back results that you are paginating. Bringing back thousands of results is inefficient and needless.

MS SQL there isn’t a simple way of doing this. The best way I have found, or my colleague Daniel has found, is to wrap a select statement inside another statement.

Loading...

Above is our full statement returning all our results. First, we need to add a row number which will allow us to know the result's position.

Loading...

That is basically it, we now just enclose this statement within another and specify which rows we’d like returned.

Loading...

Total Row Count

If you are using this for pagination, then you will need to know to total rows of this statement, without actually retrieving everything. You can do this by adding a simple addition shown below.

Loading...