how to perform 'SELECT TOP X FROM TABLE' type queries with DB2 / dashDB

82k views Asked by At

I would like to perform the equivalent of SELECT TOP 1 ... query in db2 / dashDB:

 SELECT TOP 1 * FROM customers

How can I achieve this?

2

There are 2 answers

0
Chris Snow On BEST ANSWER

You can achieve this query using the FETCH FIRST x ROWS ONLY statement, E.g.

SELECT * FROM customers FETCH FIRST 1 ROWS ONLY
0
AVP On

Another way on dashDB, and more easy for my opinion is to use the 'limit n', E.g.

SELECT * FROM customers LIMIT 1