in Turkish. Basically, it's a parameterized wrapper query
which returns rows in an interval among the results
of a given query.
It's possible to implement this the same way in
both Sql Server 2005 and Oracle 10i. I had tested it quite
well to assure that it's better than alternative methods.
I had implemented this solution for our XSLT-enabled
data and view framework for asp.net 2.0, while I was
working in Netsis.
Assumed that your raw query is:
SELECT * FROM friends;
And you need just last 10 records from a 4million-records
table. (you're very popular)
You need to wrap it this way:
RawTable as ( SELECT * FROM friends ),
(SELECT *, ROW_NUMBER() OVER
(ORDER BY @@IDENTITY) AS rownum
SELECT * FROM NumberedTable
WHERE rownum <> 3499990
As far as I can remember, It was quite better than these
- Server-side cursors of ADO.NET on SQL2005
- Embedded subqueries with two seperate SELECT TOP N
And using ROW_NUMBER() over @@IDENTITY keyword
had helped a lot, instead of giving it a name of a column
to order. It was both fast and generic.
Use responsibly :)