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?
1) Using Db2 FETCH clause to get the top-N rows The ORDER BY clause sorts books by ratings from high to low. The FETCH clause picks only the first 10 rows, which have the highest ratings.
You can specify the fetch clause in a SELECT statement to limit the number of rows in the result table of a query.
The SQL COUNT() function returns the number of rows in a table satisfying the criteria specified in the WHERE clause. It sets the number of rows or non NULL column values.
You can achieve this query using the FETCH FIRST x ROWS ONLY statement, E.g.
SELECT * FROM customers FETCH FIRST 1 ROWS ONLY
Another way on dashDB, and more easy for my opinion is to use the 'limit n', E.g.
SELECT * FROM customers LIMIT 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With