Skip to the content.
< PREVIOUS   NEXT >

LIMIT, TOP CLAUSE

The SELECT TOP clause and Limit is used to specify the number of records to return.

IMPORTANT: Not all database systems support the SELECT TOP clause. MySQL supports the LIMIT clause to select a limited number of records, while Oracle uses FETCH FIRST n ROWS ONLY and ROWNUM.

SQL SERVER / MS ACCESS SYNTAX:

SELECT TOP number|percent column_name(s)
FROM table_name
WHERE condition;

MySQL SYNTAX:

SELECT column_name(s)
FROM table_name
WHERE condition
LIMIT number;

ORACLE 12 SYNTAX:

SELECT column_name(s)
FROM table_name
ORDER BY column_name(s)
FETCH FIRST number ROWS ONLY;

EXAMPLE

Suppose there is a Table name as “CustomerComplaint” having CustomerID, CustomerName, ProductName Issue, City, PostalCode and Country as columns.


SQL statement selects the first three records from the “CustomerComplaint” table




EXAMPLE USING WHERE CLAUSE

Suppose there is a Table name as “CustomerComplaint” having CustomerID, CustomerName, ProductName Issue, City, PostalCode and Country as columns.


SQL statement selects the first three records from the “CustomerComplaint” table, where the country is “Germany”




< PREVIOUS   NEXT >

HOME