Limiting the number of records in a SELECT statement
As of DB2 Version 7 you can use the FETCH FIRST n ROWS ONLY clause. By appending this clause to your SQL SELECT...
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
statement you will limit the number of rows returned to the value specified for "n". For example, the following SQL statement will limit the number of rows returned to 10:
SELECT FIRSTNAME, LASTNAME, ADDRESS, CITY, STATE, ZIP FROM CUSTOMER WHERE ACCTNO > 10 FETCH FIRST 10 ROWS ONLY;
For More Information
- Dozens more answers to tough DB2 questions from Craig Mullins are available.
- The Best IBM DB2 Web Links: tips, tutorials, scripts, and more.
- Have a DB2 tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical DB2 questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.