Q
Problem solve Get help with specific problems with your technologies, process and projects.

Limiting the number of records in a SELECT statement

How do I limit the number of records in a SELECT statement in DB2 SQL? Something similar to the TOP command in SQL?

As of DB2 Version 7 you can use the FETCH FIRST n ROWS ONLY clause. By appending this clause to your SQL SELECT...

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

This was last published in November 2002

Dig Deeper on IBM DB2 management

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchAWS

SearchContentManagement

SearchOracle

SearchSAP

SearchSQLServer

Close