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

Dig Deeper on IBM DB2 management

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchAWS

SearchContentManagement

SearchOracle

SearchSAP

SearchSQLServer

Close