{"id":2099,"date":"2013-06-25T05:38:26","date_gmt":"2013-06-25T05:38:26","guid":{"rendered":"http:\/\/www.withdata.com\/ad\/?p=2099"},"modified":"2017-04-20T11:07:54","modified_gmt":"2017-04-20T11:07:54","slug":"the-db2-equivalent-for-the-mysql-limit","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/db2\/the-db2-equivalent-for-the-mysql-limit.html","title":{"rendered":"The DB2 equivalent for the MySQL Limit"},"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>And in DB2, use this query:<\/p>\n<pre>SELECT * FROM\r\n(SELECT * FROM sometable\r\nORDER BY name DESC fetch first {start} rows only ) AS mini\r\nORDER BY mini.name ASC fetch first {total} rows only<\/pre>\n<pre>SELECT * FROM\r\n(SELECT * FROM sometable\r\nORDER BY name DESC fetch first 20 rows only ) AS mini\r\nORDER BY mini.name ASC fetch first 10 rows only<\/pre>\n<p>In Oracle: <a href=\"https:\/\/www.withdata.com\/blog\/oracle\/how-to-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering.html\">https:\/\/www.withdata.com\/blog\/oracle\/how-to-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering.html<\/a> .<\/p>\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 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\/3885193\/equivalent-of-limit-for-db2\">http:\/\/stackoverflow.com\/questions\/3885193\/equivalent-of-limit-for-db2<\/a>\u00a0.<\/p>\n<p>Some DB2 tools you can try: <a href=\"https:\/\/www.withdata.com\/db2\/\"> https:\/\/www.withdata.com\/db2\/<\/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 And in DB2, use this query: SELECT * FROM (SELECT * FROM sometable ORDER BY name DESC fetch first {start} rows only ) AS mini ORDER BY mini.name ASC fetch first {total} rows only SELECT * FROM [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[1318,289],"class_list":["post-2099","post","type-post","status-publish","format-standard","hentry","category-db2","tag-db2","tag-equivalent-for-the-mysql-limit"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2099","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=2099"}],"version-history":[{"count":8,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2099\/revisions"}],"predecessor-version":[{"id":6456,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/2099\/revisions\/6456"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=2099"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=2099"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=2099"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}