Brought to you by molecularsciences.org.
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 License.
This publication may not be redistributed without this notice.

Limiting query results in DB2

DB2 provides the FETCH FIRST command to limit query results.

select * from mytable fetch first 10 rows only;

To get the first 10 by column

select * from mytable order by id fetch first 10 rows only;

To get the last 10 by column

select * from mytable order by id desc fetch first 10 rows only;