Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Limit Keyword in SQL

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 168
    Comment on it

    By default, all results that satisfy the conditions specified in the SQL statement are returned. However, this may not always be what we want, as sometimes we only want to retrieve a subset of records.

     

    In MySQL, this is accomplished using the LIMIT keyword.

     

    [SQL Statement 1]
    LIMIT [N];

     

    where [N] is the number of records to be returned. Please note that the ORDER BY clause is usually included in the SQL statement.

     

     

    Store_Name Sales Txn_Date
    India 1500 Jan-05-1999
    China 250 Jan-07-1999
    Australia 300 Jan-08-1999
    USA 700 Jan-08-1999

     

    This table include the details regarding the store details country wise.

     

     

    SELECT Store_Name, Sales, Txn_Date
    FROM Store_Information
    ORDER BY Sales DESC
    LIMIT 2;

     

    In this query, we have restricted the details to be shown by only to the level of two rows.

     

    Store_Name Sales Txn_Date
    India 1500 Jan-05-1999
    USA 700 Jan-08-1999

     

 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: