Q
Problem solve Get help with specific problems with your technologies, process and projects.

Returning a specified number of rows

How do I write a query that can return a specific number of rows? Say, base on the constant that I set, I can either...

return 20 rows, 30 rows from a table (or multiple tables)? Thanks.


If you're using SQL/Server or MS Access, use the TOP keyword --

select top 20 foo, bar
  from thetable

If you're using MySQL, use the LIMIT keyword --

select foo, bar
  from thetable
 limit 20

If you're using Oracle, use ROWNUM or RANK() as explained in "Performing top-N queries in Oracle".

For More Information


This was last published in May 2001

Dig Deeper on Oracle and SQL

PRO+

Content

Find more PRO+ content and other member only offers, here.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide

SearchDataCenter

SearchContentManagement

SearchFinancialApplications

Close