Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQL Tutorial -> Sql Select Top

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 100
    Comment on it

    <-- Chapter 21: SQL Injection

    Chapter 22

    SQL Select Top


    SQL Select Top clause is used to retrieve TOP N number of Records or X percent of Records from database table.


    Note: All database systems does not support the SELECT TOP clause.

    Lets see an example from the below table "employees" :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000
    104 JKL E-104 CEO 12000
    105 MNO E-105 Software Developer 100000

    SELECT TOP SQL syntax :-


    Following is an example of SQL Server


    SELECT TOP 3 *
    FROM `employees`;
    

    Now run the above SQL query, we will see the output below :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000

    Now we can see here, Top 3 Rows are displayed.


    SELECT TOP PERCENT SQL syntax :-


    Following is an example of MYSQL


    SELECT *
    FROM `employees`
    LIMIT 3;
    

    Now run the above SQL query, we will see the output below :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000

    Now we can see here, Top 3 Rows are displayed.


    If we are using ORACLE, Following is an example :-


    SELECT * 
    FROM `employees`
    WHERE ROWNUM <= 3;
    

    Now run the above SQL query, we will see the output below :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000

    Now we can see here, Top 3 Rows are displayed.


    SELECT TOP 50 PERCENT * 
    FROM `employees`;
    

    Now run the above SQL query, we will see the output below :-


    employee_id name code designation salary
    101 ABC E-101 Engineer 12000
    102 DEF E-102 Doctor 8000
    103 GHI E-103 Software Developer 8000

    Now we can see here, Top 50 Percent Rows are displayed.


    Chapter 23: SQL Wildcards -->

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: