How can I write this query without TOP and Limit only use the SQL
Asked
Active
Viewed 40 times
-4
-
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
- 19,824
- 17
- 99
- 186

Bob Jarvis - Слава Україні
- 48,992
- 9
- 77
- 110