Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
I wasn't in a position to try out these queries, and there you go... the Oracle one doesn't work (unless an index produces the right sorting order) because the ROWNUM condition is applied before sorting. The ANSI SQL way should still work for Oracle though.Originally posted by Peter den Haan:
The least resource-intensive way is of course to make sure the database returns exactly those records you want to show. [...]
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
CJP (Certifiable Java Programmer), AMSE (Anti-Microsoft Software Engineer)
Author of Posts in the Saloon
Originally posted by Gerry Giese:
Peter, would the sorting be applied before ROWNUM if you selected against a sorted view?
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Originally posted by Peter den Haan:
The least resource-intensive way is of course to make sure the database returns exactly those records you want to show. To retrieve n records, numbers k to l inclusive (i.e. l-k=n-1):
ANSI SQL:
SELECT fields
FROM tables t1
WHERE condition AND
(SELECT COUNT(*)
FROM tables t2
WHERE condition AND
t2.order <= t1.order) BETWEEN k AND l
ORDER BY order ASC
Replace "fields", "tables", "condition" and "order" by the appropriate clauses. Performance will depend on the intelligence of your database's optimiser.
- Peter
I have seen things you people would not believe, attack ships on fire off the shoulder of Orion, c-beams sparkling in the dark near the Tennhauser Gate. All these moments will be lost in time, like tears in the rain.
Oh sure, it's a tiny ad, but under the right circumstances, it gets bigger.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|