Developing By Me

Project Development and Design

TOP and LIMIT

  TOP or LIMIT are used to limit the results to a specific number of rows to be returned. The value can be from 1 to the maximum number of rows in the table. It is also possible to retrieve a percent of the rows on SQL Server. The following table shows how these two clause options can be defined:

 

SQL Query Description SQL Database
SELECT TOP 1 * Returns all fields from the first row found SQL Server
SELECT TOP 10 PERCENT * Returns all fields from the top 10% of all rows found SQL Server
SELECT *FROM table1LIMIT 1 Returns all fields from the first row found MySQL, PostgreSQL
SELECT *FROM table1WHERE ROWNUM <= 1 Returns the first row found Oracle

 

%d bloggers like this: