-3

How can I write this query without TOP and Limit only use the SQL

a_horse_with_no_name
  • 440,273
  • 77
  • 685
  • 758
  • 1
    Possible 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 Answers1

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

dbfiddle here

halfer
  • 18,701
  • 13
  • 79
  • 158