Skip to Main Content
IBM Power Ideas Portal


This portal is to open public enhancement requests against IBM Power Systems products, including IBM i. To view all of your ideas submitted to IBM, create and manage groups of Ideas, or create an idea explicitly set to be either visible by all (public) or visible only to you and IBM (private), use the IBM Unified Ideas Portal (https://ideas.ibm.com).


Shape the future of IBM!

We invite you to shape the future of IBM, including product roadmaps, by submitting ideas that matter to you the most. Here's how it works:

Search existing ideas

Start by searching and reviewing ideas and requests to enhance a product or service. Take a look at ideas others have posted, and add a comment, vote, or subscribe to updates on them if they matter to you. If you can't find what you are looking for,

Post your ideas
  1. Post an idea.

  2. Get feedback from the IBM team and other customers to refine your idea.

  3. Follow the idea through the IBM Ideas process.


Specific links you will want to bookmark for future use

Welcome to the IBM Ideas Portal (https://www.ibm.com/ideas) - Use this site to find out additional information and details about the IBM Ideas process and statuses.

IBM Unified Ideas Portal (https://ideas.ibm.com) - Use this site to view all of your ideas, create new ideas for any IBM product, or search for ideas across all of IBM.

ideasibm@us.ibm.com - Use this email to suggest enhancements to the Ideas process or request help from IBM for submitting your Ideas.

Status Future consideration
Workspace IBM i
Categories Db2 for i
Created by Guest
Created on Sep 1, 2025

FETCH LAST n ROWS ONLY Support in SQL for IBM i

FETCH LAST n ROWS ONLY Support in SQL for IBM i


Summary

Currently, DB2 for i allows developers to fetch the first n rows of a result set using the FETCH FIRST n ROWS ONLY clause. However, there is no direct equivalent syntax to fetch the last n rows in ascending order.

Problem
To retrieve the last rows, developers must currently reverse the sort order and then use FETCH FIRST n ROWS ONLY. For example:

SELECT *
FROM my_table
ORDER BY date_column DESC
FETCH FIRST 5 ROWS ONLY;

While this works, it is not intuitive: the query expresses “first rows in descending order” rather than the actual intent, which is “last rows in ascending order.” This creates unnecessary cognitive overhead and reduces code readability.

Proposed Enhancement
Introduce support for a FETCH LAST n ROWS ONLY clause. This would allow developers to express their intent directly, making queries more natural and self-explanatory.

Example

SELECT *
FROM my_table
ORDER BY date_column
FETCH LAST 5 ROWS ONLY;

Benefits

  • Improves query readability and clarity.

  • Reduces the need for query rewrites with reversed ORDER BY logic.

  • Aligns with developer expectations when working with time-ordered or sequential data.

  • Increases productivity and reduces the likelihood of errors in SQL code.

Idea priority High
  • Admin
    Carmelita Ruvalcaba
    Sep 23, 2025

    The CAAC has reviewed this IBM Idea and recommends that IBM not implement this request.

    There is no execution advantage to ordering ascending vs descending, so there is no advantage to providing the requested syntax.

    Background: The COMMON Americas Advisory Council (CAAC) members have a broad range of experience in working with small and medium-sized IBM i customers. CAAC has a key role in working with IBM i development to help assess the value and impact of individual IBM Ideas on the broader IBM i community and has therefore reviewed your Idea.

    For more information about CAAC, see www.common.org/caac

    Carmelita Ruvalcaba - CAAC Program Manager

  • Guest
    Sep 12, 2025
    IBM will use this Idea as input to planning, but no commitment is made or implied. This Idea will be updated in the future if IBM implements it.

    Db2 for i development team
    IBM Power Systems Development
  • Guest
    Sep 4, 2025

    I suspect this would be difficult to implement.    Since the underlying data may be changing, and the request is to get the data in ascending order, the last 10 rows may start with a particular row, but then a new row is introduced (or one is deleted) and now there are 11 or 9 rows from the first row presented.  This would  only work if IBM locked all the rows to be returned to prevent delete and prevented any new rows from being inserted that that become part of the set (or knowing to skip those new rows as part of the output).