SQL: Limiting the Number of Rows Returned

SQL Cookbook – O’Reilly Media

Chapter 1 Retrieving Records: Limiting the Number of Rows Returned.


Problem

You want to limit the number of rows returned in your query. You are not concerned with the order; any n rows will do.


Solution

Use the built-in function provided by your database to control the number of rows returned.


DB2



MySQL and PostgreSQL

Do the same thing in MySQL and PostgreSQL using LIMIT:
select * from emp limit 5
Oracle



SQL Server


Discussion


Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.