codescracker


sql

SQL Select Top



« Previous Tutorial Next Tutorial »


SQL SELECT TOP clause is used to specify the number of records to return.

Note - The SQL SELECT TOP clause isn't supported by all database systems.

Here are the general forms of the SELECT TOP clause in SQL for different-different databases. Let's first start with SQL and Microsoft Access Databases.

For SQL Server / MS Access Databases

Here is the general form of the SELECT TOP clause in SQL for SQL Server and MS Access Database:

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

For MySQL Database

Here is the general form of the SELECT TOP clause in SQL for MySQL Database:

SELECT column_name(s)
FROM table_name
LIMIT number;

For Oracle Database

Here is the general form of the SELECT TOP clause in SQL for Oracle database:

SELECT column_name(s)
FROM table_name
WHERE ROWNUM <= number;

SQL SELECT TOP Clause Example

Here is an example of SELECT TOP clause in SQL. The following SQL statement selects the first three records from the table "Customers"

SELECT TOP 3 * FROM Customers;

It will display the detail of the top 3 customers.

SQL SELECT TOP PERCENT Example

The following SQL statement selects the first 50% of the records from the table "Customers"

SELECT TOP 50 PERCENT * FROM Customers;

After querying the above SQL statements, it will display the 50% (half of the total number of customer present in the CUSTOMERS table) customer's record from the top


« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test