How can I write this query without TOP and Limit only use the SQL
Asked
Active
Viewed 38 times
-3
-
1Possible duplicate of [How do I limit the number of rows returned by an Oracle query after ordering?](https://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering) – OldProgrammer Sep 23 '19 at 02:05
-
Please do a bit of searching before posting a question. thanks – OldProgrammer Sep 23 '19 at 02:05
1 Answers
2
You just sort the data one way, grab the records you want, then sort it the other way:
SELECT SOME_FIELD
FROM (SELECT st.*
FROM SOME_TABLE st
ORDER BY SOME_FIELD DESC)
WHERE ROWNUM <= 7
ORDER BY SOME_FIELD ASC
halfer
- 18,701
- 13
- 79
- 158
Bob Jarvis - Reinstate Monica
- 45,294
- 8
- 73
- 102