{"id":2088,"date":"2013-06-25T04:30:08","date_gmt":"2013-06-25T04:30:08","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=2088"},"modified":"2017-04-20T10:46:54","modified_gmt":"2017-04-20T10:46:54","slug":"how-to-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/oracle\/how-to-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering.html","title":{"rendered":"How to limit the number of rows returned by an Oracle query after ordering"},"content":{"rendered":"<p>In MySQL, you can use &#8220;Limit n,m&#8221;, like this:<\/p>\n<pre>select *\r\nfrom sometable\r\norder by name\r\nlimit 20,10<\/pre>\n<p>How to do in Oracle?<\/p>\n<pre>select * from\r\n( select a.*, ROWNUM rnum from\r\n  ( &lt;your_query_goes_here, with order by&gt; ) a\r\n  where ROWNUM &lt;= :MAX_ROW_TO_FETCH )\r\nwhere rnum  &gt;= :MIN_ROW_TO_FETCH<\/pre>\n<p>like:<\/p>\n<pre>select * from\r\n( select a.*, ROWNUM rnum from\r\n  ( select * from sometable order by name ) a\r\n  where ROWNUM &lt;= 30)\r\nwhere rnum  &gt;= 20<\/pre>\n<p>In SQL Server:\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/sql-server\/the-sql-server-equivalent-for-the-mysql-limit.html\">https:\/\/www.withdata.com\/blog\/sql-server\/the-sql-server-equivalent-for-the-mysql-limit.html<\/a>\u00a0.<\/p>\n<p>In DB2:\u00a0<a href=\"https:\/\/www.withdata.com\/blog\/db2\/the-db2-equivalent-for-the-mysql-limit.html\">https:\/\/www.withdata.com\/blog\/db2\/the-db2-equivalent-for-the-mysql-limit.html<\/a>\u00a0.<\/p>\n<p>In Mysql: <a href=\"https:\/\/www.withdata.com\/blog\/mysql\/how-to-limit-the-number-of-rows-returned-by-an-mysql-query.html\">https:\/\/www.withdata.com\/blog\/mysql\/how-to-limit-the-number-of-rows-returned-by-an-mysql-query.html<\/a> .<\/p>\n<p>In Sqite: <a href=\"https:\/\/www.withdata.com\/blog\/sqlite\/how-to-limit-the-number-of-rows-returned-by-an-sqlite-query.html\">https:\/\/www.withdata.com\/blog\/sqlite\/how-to-limit-the-number-of-rows-returned-by-an-sqlite-query.html<\/a> .<\/p>\n<p>In PostgreSQL: <a href=\"https:\/\/www.withdata.com\/blog\/postgresql\/how-to-limit-the-number-of-rows-returned-by-an-postgresql-query.html\">https:\/\/www.withdata.com\/blog\/postgresql\/how-to-limit-the-number-of-rows-returned-by-an-postgresql-query.html<\/a> .<\/p>\n<p>You can visit this page for more information:\u00a0<a href=\"http:\/\/stackoverflow.com\/questions\/470542\/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering\">http:\/\/stackoverflow.com\/questions\/470542\/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering<\/a><\/p>\n<p>Some Oracle tools you can try: <a href=\"https:\/\/www.withdata.com\/oracle\/\"> https:\/\/www.withdata.com\/oracle\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In MySQL, you can use &#8220;Limit n,m&#8221;, like this: select * from sometable order by name limit 20,10 How to do in Oracle? select * from ( select a.*, ROWNUM rnum from ( &lt;your_query_goes_here, with order by&gt; ) a where ROWNUM &lt;= :MAX_ROW_TO_FETCH ) where rnum &gt;= :MIN_ROW_TO_FETCH like: select * from ( select a.*, [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32],"tags":[289,1325],"class_list":["post-2088","post","type-post","status-publish","format-standard","hentry","category-oracle","tag-equivalent-for-the-mysql-limit","tag-oracle"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2088","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=2088"}],"version-history":[{"count":10,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2088\/revisions"}],"predecessor-version":[{"id":6422,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2088\/revisions\/6422"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=2088"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=2088"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=2088"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}