TOP clause | SQL Tutorial and Query Example

Text copied!

TOP clause


  • TOP clause :

    TOP clause is used to fetch specified number or percentage of rows from a table.

    The syntax of the TOP clause generally looks like this :
    Here's an example of how you might use the TOP clause :

    1. Let's assume we have a table named "[Employees]".

    Case - 1 :

    Let's assume you want to retrieve only specific number of rows from [Employees] table.

    SELECT TOP n column_name(s)
    FROM table_name;
            
    Case - 2 :

    Let's assume you want to retrieve only specific percentage of rows from [Employees] table.

    SELECT TOP n PERCENT column_name(s)
    FROM table_name;
            
    TOP clause
    SELECT TOP 3 *
    FROM [Employees];
            
    TOP clause
    SELECT TOP 40 PERCENT *
    FROM [Employees];
            
    TOP clause

    Frequently Asked Questions :

    The TOP clause in SQL specifies the number of rows to return from a query result.
    The TOP n clause in SQL Server limits the result set to the specified number of rows.
    An alternative to the TOP clause in other database systems like MySQL is the LIMIT clause.
    To select the top 5 records in SQL, you can use the "SELECT TOP 5" statement in SQL Server.