Quick Tip: Limit The Number Of Rows Returned From A SQL Query
Share
This is pretty basic, but I had to look up the syntax to use for SQL on IBM DB2 so I thought I’d write a quick tip.
Limiting the number of records returned from a query is really helpful when querying a table with millions of records and you expect a large amount of data back. I use it a lot when determining what my ‘where’ statement should look like. My workflow usually goes something like this:
- I know the data is in table F0911 (yeah, it’s a big one)
- I only need records associated with a particular Document Number but I don’t remember what that column is named.
- So, I start with this:
SELECT * FROM PRODDTA.F0911 FETCH FIRST 10 ROW ONLY - That way I get the column names and can continue working on the ‘WHERE’ clause.
Below are examples of ways to limit the number of results in your SQL query:
IBM DB2 Syntax
SELECT * FROM PRODDTA.F0911 FETCH FIRST 10 ROW ONLY;
SQL Server Syntax
SELECT TOP 10 FROM PRODDTA.F0911;
Oracle Syntax
SELECT * FROM PRODDTA.F0911 WHERE ROWNUM <= 10;
Source: IBM Knowledge Center | W3Schools.com
If you have any questions, comments or ideas, please leave them in the comments.
Author
Stewart Schatz
Average Rating
One thought on “Quick Tip: Limit The Number Of Rows Returned From A SQL Query”
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.
More Stories
How to Use the rsync Command to Sync Files and Directories on Linux
The rsync command is one of the most powerful tools in the Linux toolkit for syncing files and directories. Whether...
Quick Tip: Determine Active Directory Account Status From The Windows Commandline
Use the following command to Determine Active Directory Account Status from the Windows Commandline without Powershell or any special software....
Where Is Java Installed?
Below are a few commands that can be run to determine where Java is installed on each Operating System: Windows:...
Quick Tip: IBM Navigator for i Default URL
This is a really quick one but I keep forgetting it: http://<SERVERNAME>:2004/ibm/console
Windows God Mode… What!?!
Windows God Mode is a hidden feature in the Windows operating system that allows users to access all of the system’s control panel options and settings in a single place.
A Better SMTP Test
Several years ago, I posted about an SMTP Test that I was using. Well, lately, I've needed something with a...
What’s up mates, nice article and nice urging commented here,
I am genuinely enjoying by these.